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 )
}
}
for [5, 7], [2, 5, 7, 9, 10] -> @ints {
say "EKGs of (@ints[]) converge at term {$_+1}" with converge-at(@ints);
}</lang>
{{out}}
<pre>
EKG(
EKG(
EKG(
EKG(
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}}==
|