Problem 313. Pythagorean perfect squares: find the square of the hypotenuse and the length of the other side
Given the square root of a square number, seed, and a range, n, find the square number, Z as well as the other side, y, the square root of a square number i.e. return the hypotenuse squared as well as the length of the other side. Note that n is the number of squares to search through starting with one.
HINT: Z = seed^2 + y^2 where Z = z^2, find Z first and then y.
Note that Z, seed^2 and y^2 are all perfect squares.
>> [z s] = findPerfectZ(3,6)
z = 25
s = 4
>>
Solution Stats
Problem Comments
-
1 Comment
There's a problem with the solution suite. For seed=12 and n=16, the proposed answer of 5, 12, 13 as a Pythagorean triple is indeed a good one. However, 9, 12, 15 is equally valid but not included as an answer. To avoid this, I would suggest changing the problem so that it requires finding the answer with the minimum Z^2 to avoid ambiguity.
Solution Comments
Show commentsProblem Recent Solvers53
Suggested Problems
-
Maximum running product for a string of numbers
2160 Solvers
-
230 Solvers
-
Convert a numerical matrix into a cell array of strings
1830 Solvers
-
Remove white space from the string
194 Solvers
-
5052 Solvers
More from this Author16
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!