Coprime triplets: Difference between revisions

Added Perl
(Added AppleScript.)
(Added Perl)
Line 293:
47 20 33 49 26 45
</pre>
 
=={{header|Perl}}==
{{libheader|ntheory}}
<lang perl>use strict;
use warnings;
use feature <state say>;
use ntheory 'gcd';
use List::Util 'first';
use List::Lazy 'lazy_list';
use enum qw(False True);
use constant Inf => 1e5;
 
my $ct = lazy_list {
state @c = (1, 2);
state %seen = (1 => True, 2 => True);
state $min = 3;
my $g = $c[-2] * $c[-1];
my $n = first { !$seen{$_} and gcd($_,$g) == 1 } $min .. Inf;
$seen{$n} = True;
$min = first { !$seen{$_} } $min .. Inf;
push @c, $n;
shift @c
};
 
my @ct;
do { push @ct, $ct->next() } until $ct[-1] > 50; pop @ct;
say join ' ', @ct</lang>
{{out}}
<pre>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</pre>
 
=={{header|Phix}}==
2,392

edits