Cody - "server not available" when submitting solution on prime numbers question
6 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Cris LaPierre
2025 年 6 月 3 日
編集済み: Cris LaPierre
2025 年 6 月 4 日
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 件のコメント
Cris LaPierre
2025 年 6 月 4 日
編集済み: Cris LaPierre
2025 年 6 月 4 日
You can get a rough estimate by observing the progress (indicated by the line numbers in a live script).

Cris LaPierre
2025 年 6 月 4 日
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.
その他の回答 (1 件)
the cyclist
2025 年 6 月 3 日
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.
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!