Problem 1103. Right Triangle Side Lengths (Inspired by Project Euler Problem 39)
Solution Stats
Problem Comments
-
4 Comments
Hi Team,
I am getting error after submitting as,
"We're sorry, but something went wrong. We've been notified about this issue and we'll take a look at it shortly"
But completion bar has been incremented.
Thanks and Have a Good DaY
Well I don't know why I can't pass the test
could anyone help
function c = right_triangle_sides(p)
c = {};
k=1;
for i=1:ceil(p/3)
for j=i:ceil((p-i)/2)
if i^2+j^2==(p-i-j)^2
c(k)=mat2cell([i j p-i-i],1);
k=k+1;
end
end
end
end
To creator of this group,
Please check the test case 3 in the Problem of calculating side length from area of triangle. One ';' is missing which is not allowing the case to pass for correct solution.
This problem really highlights problems with the Cody scoring system. The score using a double for loop to brute force the lengths beats out a single for loop using equations. I tested my code in Matlab vs double loops and it's faster than most double loops I tested by several orders of magnitude for larger numbers (p>1000). There is also some sort of caching going on where my code gets orders of magnitude faster again if ran a few times vs most double for loops.
There is one exception with a double loop that is really fast by Hung Hoang. They use the for loops in a way that doesn't make it O^2.
Solution Comments
Show commentsProblem Recent Solvers1748
Suggested Problems
-
Which values occur exactly three times?
5076 Solvers
-
2340 Solvers
-
484 Solvers
-
1289 Solvers
-
Natural numbers in string form
1390 Solvers
More from this Author56
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!