Special pythagorean triplet: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) (→{{header|Raku}}: Add a Raku example) |
(→{{header|Wren}}: Added a further version.) |
||
Line 130: | Line 130: | ||
a * b * c = 31875000 |
a * b * c = 31875000 |
||
</pre> |
</pre> |
||
<br> |
|||
Incidentally, even though we are '''told''' there is only one solution, it is almost as quick to verify this by observing that, since a < b < c, the maximum value of a must be such that 3a + 2 = 1000 or max(a) = 332. The following version ran in 0.015 seconds and, of course, produced the same output: |
|||
<lang wren>for (a in 3..332) { |
|||
var b = a + 1 |
|||
while (true) { |
|||
var c = 1000 - a - b |
|||
if (c <= b) break |
|||
if (a*a + b*b == c*c) { |
|||
System.print("a = %(a), b = %(b), c = %(c)") |
|||
System.print("a + b + c = %(a + b + c)") |
|||
System.print("a * b * c = %(a * b * c)") |
|||
} |
|||
b = b + 1 |
|||
} |
|||
}</lang> |