EKG sequence convergence: Difference between revisions

Content added Content deleted
(→‎Python: Using math.gcd: Update w.r.t. task goal changes.)
(→‎{{header|Perl 6}}: Added stretch goal (plus a bonus case converging all EKGs), and updated to new task spec.)
Line 278: Line 278:
sub EKG ( Int $start ) { 1, $start, &next-EKG … * }
sub EKG ( Int $start ) { 1, $start, &next-EKG … * }


sub converge-at ( @ints ) {
say "EKG($_): ", .&EKG.head(30) for 2, 5, 7, 9, 10;</lang>
my @ekgs = @ints.map: &EKG;

return (2 .. *).first: -> $i {
[==] @ekgs.map( *.[$i] ) and
[===] @ekgs.map( *.head($i).Set )
}
}

say "EKG($_): ", .&EKG.head(10) for 2, 5, 7, 9, 10;

for [5, 7], [2, 5, 7, 9, 10] -> @ints {
say "EKGs of (@ints[]) converge at term {$_+1}" with converge-at(@ints);
}</lang>
{{out}}
{{out}}
<pre>
<pre>EKG(2): (1 2 4 6 3 9 12 8 10 5 15 18 14 7 21 24 16 20 22 11 33 27 30 25 35 28 26 13 39 36)
EKG(5): (1 5 10 2 4 6 3 9 12 8 14 7 21 15 18 16 20 22 11 33 24 26 13 39 27 30 25 35 28 32)
EKG(2): (1 2 4 6 3 9 12 8 10 5)
EKG(7): (1 7 14 2 4 6 3 9 12 8 10 5 15 18 16 20 22 11 33 21 24 26 13 39 27 30 25 35 28 32)
EKG(5): (1 5 10 2 4 6 3 9 12 8)
EKG(9): (1 9 3 6 2 4 8 10 5 15 12 14 7 21 18 16 20 22 11 33 24 26 13 39 27 30 25 35 28 32)
EKG(7): (1 7 14 2 4 6 3 9 12 8)
EKG(10): (1 10 2 4 6 3 9 12 8 14 7 21 15 5 20 16 18 22 11 33 24 26 13 39 27 30 25 35 28 32)</pre>
EKG(9): (1 9 3 6 2 4 8 10 5 15)
EKG(10): (1 10 2 4 6 3 9 12 8 14)
EKGs of (5 7) converge at term 21
EKGs of (2 5 7 9 10) converge at term 45
</pre>


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