Coprime triplets: Difference between revisions

→‎{{header|Raku}}: Add a Raku entry
(add FreeBASIC)
(→‎{{header|Raku}}: Add a Raku entry)
Line 76:
47 20 33 49 26 45
</pre>
 
=={{header|Raku}}==
<lang perl6>my @coprime-triplets = 1,2, {
state %seen = 1, True, 2, True;
sink $^a, $^b;
my $n = (3 .. *).first: { !%seen{$_} && ($_ gcd $a == 1) && ($_ gcd $b == 1) }
%seen{$n} = True;
$n
} … *;
 
put "Coprime triplets less than 50:\n",
@coprime-triplets[^(@coprime-triplets.first: * > 50, :k)].batch(10)».fmt("%4d").join: "\n";
 
put "\n1000th through 1025th Coprime triplet:\n",
@coprime-triplets[999..1024].batch(10)».fmt("%4d").join: "\n";</lang>
{{out}}
<pre>Coprime triplets less than 50:
1 2 3 5 4 7 9 8 11 13
6 17 19 10 21 23 16 15 29 14
25 27 22 31 35 12 37 41 18 43
47 20 33 49 26 45
 
1000th through 1025th Coprime triplet:
1355 682 1293 1361 680 1287 1363 686 1299 1367
688 1305 1369 692 1311 1373 694 1317 1375 698
1323 1381 704 1329 1379 706</pre>
 
=={{header|Ring}}==
10,333

edits