EKG sequence convergence: Difference between revisions

→‎{{header|Perl 6}}: Added stretch goal (plus a bonus case converging all EKGs), and updated to new task spec.
(→‎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:
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(3010) for 2, 5, 7, 9, 10;</lang>
 
for [5, 7], [2, 5, 7, 9, 10] -> @ints {
say "EKGs of (@ints[]) converge at term {$_+1}" with converge-at(@ints);
}</lang>
{{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(52): (1 5 10 2 4 6 3 9 12 8 1410 7 21 15 18 16 20 22 11 33 24 26 13 39 27 30 25 35 28 325)
EKG(75): (1 75 1410 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(97): (1 97 3 614 2 4 86 103 5 159 12 14 7 21 18 16 20 22 11 33 24 26 13 39 27 30 25 35 28 328)
EKG(109): (1 109 2 43 6 32 9 124 8 1410 7 215 15 5 20 16 18 22 11 33 24 26 13 39 27 30 25 35 28 32)</pre>
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}}==
256

edits