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 ) { |
|||
⚫ | |||
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}} |
{{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( |
EKG(2): (1 2 4 6 3 9 12 8 10 5) |
||
EKG( |
EKG(5): (1 5 10 2 4 6 3 9 12 8) |
||
EKG( |
EKG(7): (1 7 14 2 4 6 3 9 12 8) |
||
EKG( |
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}}== |