Ramanujan primes/twins: Difference between revisions

Content added Content deleted
(→‎{{header|Raku}}: Add a Raku example)
Line 335: Line 335:
"4.7s"
"4.7s"
</pre>
</pre>

=={{header|Raku}}==
Timing is informational only. Will vary by system specs and load.
<lang perl6>use ntheory:from<Perl5> <ramanujan_primes>;
use Lingua::EN::Numbers;

my @rp = ramanujan_primes(100_000_000)[^1_000_000];

for (1e5, 1e6)».Int -> $limit {
say "\nThe {comma $limit}th Ramanujan prime is { comma @rp[$limit-1]}";
say "There are { comma +(^($limit-1)).race.grep: { @rp[$_+1] == @rp[$_]+2 } } twins in the first {comma $limit} Ramanujan primes.";
}

say (now - INIT now).fmt('%.3f') ~ ' seconds';</lang>
{{out}}
<pre>The 100,000th Ramanujan prime is 2,916,539
There are 8,732 twins in the first 100,000 Ramanujan primes.

The 1,000,000th Ramanujan prime is 34,072,993
There are 74,973 twins in the first 1,000,000 Ramanujan primes.
2.863 seconds</pre>


=={{header|Wren}}==
=={{header|Wren}}==