Cody - "server not available" when submitting solution on prime numbers question

6 ビュー (過去 30 日間)
ty
ty 2025 年 6 月 3 日
編集済み: Cris LaPierre 2025 年 6 月 4 日
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?
  1. Am I right in thinking that this is due to my solution not running fast enough?
  2. 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

採用された回答

Cris LaPierre
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
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).
For a more advanced breakdown, this page talks about how to profile your code: https://www.mathworks.com/help/matlab/matlab_prog/profiling-for-improving-performance.html
Cris LaPierre
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
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.
  1 件のコメント
ty
ty 2025 年 6 月 4 日
Thank you for clarifying, it's good to know that there is a specific error code for that.
It does seem like there is a problem currently with either MATLAB or the tests set up in this problem, I was getting the same problem in a similar problem titled "List the cuban primes" which was also made by the same person.
I feel that it is some of the commands/techniques used in the tests are whats causing the problems, as I am able to submit a solution to other problems, and submitting a solution with flawed syntax on the original problem immediately returns an error relevant to the syntax error.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

製品


リリース

R2024b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by