Pythagorean triples: Difference between revisions
→{{header|Raku}}: First, brute-force solution was not restricting results to the perimeter limit.
(Added Quackery.) |
(→{{header|Raku}}: First, brute-force solution was not restricting results to the perimeter limit.) |
||
Line 4,520:
(formerly Perl 6)
{{works with|Rakudo|2018.09}}
Here is a straight-forward,
<syntaxhighlight lang="raku" line>constant limit = 100;
for [X] [^limit] xx 3 -> (\a, \b, \c) {
say [a, b, c] if a < b < c and a + b + c <= limit and a*
}</syntaxhighlight>
{{out}}
<pre style="height:25ex">[3 4 5]
[5 12 13]
[6 8 10]
[7 24 25]
[8 15 17]
[9 12 15]
[9 40 41]
[10 24 26]
[12 16 20]
[12
[15 20 25]▼
[15 36 39]▼
[16 30 34]▼
[18 24 30]
▲15 20 25
[20 21 29]▼
▲15 36 39
[21 28 35]▼
▲16 30 34
[24 32 40]▼
▲20 21 29
▲21 28 35
▲24 32 40
▲65 72 97</pre>
Here is a slightly less naive brute force implementation, but still not practical for large perimeter limits.
<syntaxhighlight lang="raku" line>my $limit = 10000;
|