Mian-Chowla sequence: Difference between revisions
Rename Perl 6 -> Raku, alphabetize, minor clean-up
Thundergnat (talk | contribs) m (Fix misspelling, add a link, remove excess whitespace) |
Thundergnat (talk | contribs) (Rename Perl 6 -> Raku, alphabetize, minor clean-up) |
||
Line 63:
:* [[oeis:A005282|OEIS:A005282 Mian-Chowla sequence]]
=={{header|Ada}}==
Line 134 ⟶ 133:
22526 23291 23564 23881 24596 24768 25631 26037 26255 27219
</pre>
=={{header|ALGOL 68}}==
Line 748 ⟶ 746:
0 1 0 0 0 0 0 0 0 0
</pre>
=={{header|Java}}==
Line 1,004 ⟶ 1,003:
0.007524 seconds (168 allocations: 404.031 KiB)
</pre>
=={{header|Kotlin}}==
{{trans|Go}}
Line 1,281:
say "First 30 terms in the Mian–Chowla sequence:\n", join(' ', @mian_chowla[ 0..29]),
"\nTerms 91 through 100:\n", join(' ', @mian_chowla[90..99]);</lang>
{{out}}▼
<pre>First 30 terms in the Mian–Chowla sequence:▼
1 2 4 8 13 21 31 45 66 81 97 123 148 182 204 252 290 361 401 475 565 593 662 775 822 916 970 1016 1159 1312▼
Terms 91 through 100:▼
22526 23291 23564 23881 24596 24768 25631 26037 26255 27219</pre>▼
=={{header|Perl 6}}==▼
<lang perl6>my @mian-chowla = 1, |(2..Inf).map: -> $test {▼
state $index = 1;▼
state %sums = 2 => 1;▼
my $next;▼
my %these;▼
@mian-chowla[^$index].map: { ++$next and last if %sums{$_ + $test}:exists; ++%these{$_ + $test} };▼
next if $next;▼
++%sums{$test + $test}; ▼
%sums.push: %these;▼
++$index;▼
$test▼
};▼
put "First 30 terms in the Mian–Chowla sequence:\n", @mian-chowla[^30];▼
put "\nTerms 91 through 100:\n", @mian-chowla[90..99];</lang>▼
{{out}}
<pre>First 30 terms in the Mian–Chowla sequence:
Line 1,520 ⟶ 1,497:
(Computation time c. 27 ms)</pre>
(formerly Perl 6)
▲<lang perl6>my @mian-chowla = 1, |(2..Inf).map: -> $test {
▲ state $index = 1;
▲ state %sums = 2 => 1;
▲ my $next;
▲ my %these;
▲ @mian-chowla[^$index].map: { ++$next and last if %sums{$_ + $test}:exists; ++%these{$_ + $test} };
▲ next if $next;
▲ ++%sums{$test + $test};
▲ %sums.push: %these;
▲ ++$index;
▲ $test
▲};
▲put "First 30 terms in the Mian–Chowla sequence:\n", @mian-chowla[^30];
▲put "\nTerms 91 through 100:\n", @mian-chowla[90..99];</lang>
▲{{out}}
▲<pre>First 30 terms in the Mian–Chowla sequence:
▲1 2 4 8 13 21 31 45 66 81 97 123 148 182 204 252 290 361 401 475 565 593 662 775 822 916 970 1016 1159 1312
▲Terms 91 through 100:
▲22526 23291 23564 23881 24596 24768 25631 26037 26255 27219</pre>
=={{header|REXX}}==
|