Pythagorean triples: Difference between revisions
Content added Content deleted
(Added Quackery.) |
(→{{header|Raku}}: First, brute-force solution was not restricting results to the perimeter limit.) |
||
Line 4,520: | Line 4,520: | ||
(formerly Perl 6) |
(formerly Perl 6) |
||
{{works with|Rakudo|2018.09}} |
{{works with|Rakudo|2018.09}} |
||
Here is a straight-forward, |
Here is a straight-forward, naïve brute force implementation: |
||
<syntaxhighlight lang="raku" line>constant limit = 100; |
<syntaxhighlight lang="raku" line>constant limit = 100; |
||
for [X] [^limit] xx 3 -> (\a, \b, \c) { |
for [X] [^limit] xx 3 -> (\a, \b, \c) { |
||
say [a, b, c] if a < b < c and a* |
say [a, b, c] if a < b < c and a + b + c <= limit and a*b + b*b == c*c |
||
}</syntaxhighlight> |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre style="height:25ex">3 4 5 |
<pre style="height:25ex">[3 4 5] |
||
5 12 13 |
[5 12 13] |
||
6 8 10 |
[6 8 10] |
||
7 24 25 |
[7 24 25] |
||
8 15 17 |
[8 15 17] |
||
9 12 15 |
[9 12 15] |
||
9 40 41 |
[9 40 41] |
||
10 24 26 |
[10 24 26] |
||
[12 16 20] |
|||
11 60 61 |
|||
12 |
[12 35 37] |
||
⚫ | |||
12 35 37 |
|||
⚫ | |||
13 84 85 |
|||
⚫ | |||
14 48 50 |
|||
[18 24 30] |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
16 63 65 |
|||
⚫ | |||
18 80 82 |
|||
⚫ | |||
20 48 52 |
|||
⚫ | |||
21 72 75 |
|||
⚫ | |||
24 45 51 |
|||
24 70 74 |
|||
25 60 65 |
|||
27 36 45 |
|||
28 45 53 |
|||
30 40 50 |
|||
30 72 78 |
|||
32 60 68 |
|||
33 44 55 |
|||
33 56 65 |
|||
35 84 91 |
|||
36 48 60 |
|||
36 77 85 |
|||
39 52 65 |
|||
39 80 89 |
|||
40 42 58 |
|||
40 75 85 |
|||
42 56 70 |
|||
45 60 75 |
|||
48 55 73 |
|||
48 64 80 |
|||
51 68 85 |
|||
54 72 90 |
|||
57 76 95 |
|||
60 63 87 |
|||
⚫ | |||
Here is a slightly less naive brute force implementation, but still not practical for large perimeter limits. |
Here is a slightly less naive brute force implementation, but still not practical for large perimeter limits. |
||
<syntaxhighlight lang="raku" line>my $limit = 10000; |
<syntaxhighlight lang="raku" line>my $limit = 10000; |