EKG sequence convergence: Difference between revisions

Content added Content deleted
(Promote to full task status.)
(→‎{{header|Perl 6}}: Added Perl 6 solution)
Line 256: Line 256:
EKG(5) and EKG(7) converge at term 21
EKG(5) and EKG(7) converge at term 21
</pre>
</pre>

=={{header|Perl 6}}==
{{works with|Rakudo Star|2018.04.1}}
<lang perl6>sub infix:<shares-divisors-with> { ($^a gcd $^b) > 1 }

sub next-EKG ( *@s ) {
return first {
@s ∌ $_ and @s.tail shares-divisors-with $_
}, 2..*;
}

sub EKG ( Int $start ) { 1, $start, &next-EKG … * }

say "EKG($_): ", .&EKG.head(10) for 2, 5, 7;</lang>
{{out}}
<pre>
EKG(2): (1 2 4 6 3 9 12 8 10 5)
EKG(5): (1 5 10 2 4 6 3 9 12 8)
EKG(7): (1 7 14 2 4 6 3 9 12 8)</pre>


=={{header|Python}}==
=={{header|Python}}==