Cuban primes: Difference between revisions

Content deleted Content added
Robbie (talk | contribs)
Thundergnat (talk | contribs)
→‎{{header|Perl 6}}: Faster prime testing, big speed boost
Line 899: Line 899:


===The task (k == 1)===
===The task (k == 1)===
Not the most efficient, but concise, and good enough for this task.
Not the most efficient, but concise, and good enough for this task. Use the ntheory library for prime testing; gets it down to around 20 seconds.
<lang perl6>sub comma { $^i.flip.comb(3).join(',').flip }
<lang perl6>use Lingua::EN::Numbers;
use ntheory:from<Perl5> <:all>;


my @cubans = lazy (1..Inf).hyper(:8degree).map({ ($_+1)³ - .³ }).grep: *.is-prime;
my @cubans = lazy (1..Inf).map({ ($_+1)³ - .³ }).grep: *.&is_prime;


put @cubans[^200]».&comma».fmt("%9s").rotor(10).join: "\n";
put @cubans[^200]».&comma».fmt("%9s").rotor(10).join: "\n";