Problem 2022. Find a Pythagorean triple
Solution Stats
Problem Comments
-
7 Comments
See Problem 1550 Can I make a right triangle ?
Thanks Tanya, have enjoyed these.
if (a==2|a==3)
flag=true;
end
The cases are very limited to make such a code valid
Thanks, enjoyed these.
I really liked this problem!
niceee
brainstormed
Solution Comments
-
1 Comment
Elegant!
-
1 Comment
Your method is wanderful,extraordinarily use the function ''choosek'',just nice!
-
1 Comment
hard one
-
1 Comment
tricky
-
1 Comment
very challenging
-
1 Comment
function flag = isTherePythagoreanTriple(a, b, c, d)
flag = false;
com_bin = nchoosek([a b c d],3);
com_bin = com_bin(:,1) .^ 2 + com_bin(:,2) .^ 2 == com_bin(:,3) .^ 2;
flag = logical(sum(com_bin));
end
-
2 Comments
M=[a,b,c,d]
c=nchoosek(M,3);
c=c(sum(c(:,1:2).^2,2)-c(:,3).^2==0,:);
if isempty(c)
flag = false;
else
flag = true;
end
function flag = isTherePythagoreanTriple(a, b, c, d)
flag = false;
com_bin = nchoosek([a b c d],3);
com_bin = com_bin(:,1) .^ 2 + com_bin(:,2) .^ 2 == com_bin(:,3) .^ 2;
flag = logical(sum(com_bin));
end
-
1 Comment
This is not a valid solution to this puzzle!!
-
3 Comments
This is a smart solution that is not cheating the system.
Logical enough!
smart!
-
3 Comments
Great work!
Lol saying great work on your own solution :P
Great work :)
Haha that's how we roll!
-
1 Comment
why the leading solution size is always 10, how could that possible?
-
1 Comment
Yeah, I know this is cheating, taking advantage of the limited test suite. I just wanted to see what the other small scores were about.
-
1 Comment
i need to change this
-
1 Comment
excellent coding skills
-
1 Comment
hardcore brute force
-
1 Comment
Should work for any case and doesn't contain str2num or regexp :)
-
1 Comment
Fifth test cannot be true because 3.5^2 = 12.25
and no integer after squaring and adding will give such result
-
3 Comments
Still without str2num or regexp
this would fail on assert(isequal(isTherePythagoreanTriple(1,4,7,9),false))
The benefit of a limited test suite.
-
1 Comment
Without using str2num or regexp
Problem Recent Solvers3856
Suggested Problems
-
421 Solvers
-
1488 Solvers
-
884 Solvers
-
608 Solvers
-
630 Solvers
More from this Author10
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!