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

4 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Swastik Sarkar
Swastik Sarkar il 25 Giu 2025
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 !

Più risposte (0)

Categorie

Scopri di più su Startup and Shutdown in Help Center e File Exchange

Prodotti


Release

R2025a

Community Treasure Hunt

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

Start Hunting!

Translated by