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

3 次查看(过去 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 CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

产品


版本

R2025a

Community Treasure Hunt

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

Start Hunting!

Translated by