Recurrent server error message while submitting solution for a given problem in Cody

4 ビュー (過去 30 日間)
Hi,
When I test it in the scratch pad, all the tests run successfully.
However, when I try to submit it -since the begining of the week now- I get the recurrent server error message :
"The server is not available. Wait a few minutes, and then retry your request. If the problem persists, contact the instructor."
Could you please help ?
Thank you
My solution by the way (even it may not be perfect, I don't see any reason it would come from here ?) :
function [pp,a,b] = PythagoreanPrime(n)
u = [];
k = 5;
while numel(u) < n
[r,a,b] = isPythagoreanPrime(k);
if r
u = cat(2,u,k);
end
k = k + 2;
end
pp = u(end);
end
function [r,a,b] = isPythagoreanPrime(p)
r = (mod(p-1,4) == 0) & isprime(p);
if r
k = 1;
while k < floor(0.5*p)
c = [k,p-k];
if sum(floor(sqrt(c)) == sqrt(c),2) == 2
a = sqrt(k);
b = sqrt(p-k);
break;
end
k = k + 1;
end
else
a = [];
b = [];
end
end

採用された回答

Swastik Sarkar
Swastik Sarkar 2025 年 6 月 25 日
I have encountered and resolved the issue you described. Upon investigation, it appears that the server error arises when the input value exceeds a certain threshold (e.g., 10,000). This is likely due to performance inefficiencies in the current implementation.
In particular, operations such as frequent use of numel() within loops and dynamic array concatenation can significantly impact execution time and memory usage. These patterns tend to scale poorly with larger inputs and may lead to server timeouts or instability.
I would recommend reviewing the algorithm with a focus on computational efficiency. Consider alternatives that reduce redundant operations and avoid dynamic memory allocation within iterative structures.
All the best !

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

製品


リリース

R2025a

Community Treasure Hunt

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

Start Hunting!

Translated by