EKG sequence convergence: Difference between revisions
Content deleted Content added
Add Factor |
Thundergnat (talk | contribs) Rename Perl 6 -> Raku, alphabetize, minor clean-up |
||
Line 287:
EKG(5) and EKG(7) converge at term 21
</pre>
=={{header|Haskell}}==
Line 616 ⟶ 615:
EKG(10): 1 10 2 4 6 3 9 12 8 14
EKGs of 5 & 7 converge at term 21</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 … * }▼
sub converge-at ( @ints ) {▼
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}}▼
<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)▼
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|Phix}}==
Line 804 ⟶ 766:
(21, [13, 17, 19, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32]),
(24, [13, 17, 19, 23, 25, 26, 27, 28, 29, 30, 31, 32])]</pre>
(formerly 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 … * }
▲sub converge-at ( @ints ) {
▲ 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}}
▲<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)
▲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|REXX}}==
|