Cody - "server not available" when submitting solution on prime numbers question
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
ty
el 3 de Jun. de 2025
Editada: Cris LaPierre
el 4 de Jun. de 2025
I am new to matlab and have been going through some of the cody problems, I finished some of the easier ones without a problem and decided to try out the group Prime Numbers III.
When I submit my solution, I get the error message "The server is not available. Wait a few minutes, and then retry your request. If the problem persists, contact the instructor."
I'm guessing this means that my solution is not fast enough?
- Am I right in thinking that this is due to my solution not running fast enough?
- How can I improve the speed of my solution?
Below is my solution to the problem list the moran numbers.
function y = Moran(n)
i = 1:n
for idx = 1:n
a = num2str(idx);
b(idx) = idx/sum(a-'0');
end
b
y = i(ismember(b,primes(n))==1)
end
I also got copilot to generate the below version where there is no for-loop but I dont really understand what it's doing, and seems like it's not fast enough either.
function y = Moran(n)
i = 1:n;
a = arrayfun(@num2str, i, 'UniformOutput', false);
b = cellfun(@(x) str2double(x) / sum(x - '0'), a);
y = i(ismember(b, primes(n)));
end
0 comentarios
Respuesta aceptada
Cris LaPierre
el 3 de Jun. de 2025
Editada: Cris LaPierre
el 4 de Jun. de 2025
Currently, I can generate the same error if I submit an infinite while loop. This does suggest the error might be related to long execution times, though it is returning the error quicker than I'd expect.
In addition, it is not an issue with the code you have written. When I test the problem in desktop MATLAB, your solution passes all the tests. However, I found that Test 3 takes an exceptionally long time to run (almost 2 mins).
5 comentarios
Cris LaPierre
el 4 de Jun. de 2025
Editada: Cris LaPierre
el 4 de Jun. de 2025
You can get a rough estimate by observing the progress (indicated by the line numbers in a live script).

Cris LaPierre
el 4 de Jun. de 2025
I did notice other solutions used num2str successfully. They included the second optional argument to specify the format. Something like this:
num2str(A','%08d')'-'0');
However, this alone isn't enough to fix your original code.
Más respuestas (1)
the cyclist
el 3 de Jun. de 2025
That error does not mean your solution was not fast enough. (As I recall, there is a separate message telling you if you solution timed out.)
MathWorks has been undergoing a ransomware attack. You can see status updates. Cody is currently listed as operating normally, but it is possible that you got caught in that.
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!