Skip to content
This repository
tree: 3e5a26927e
Fetching contributors…

Cannot retrieve contributors at this time

file 42 lines (34 sloc) 0.584 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
use 5.10.0;

my @primes = (2,3);
my @spokes = (0);
my $spix = 1;
my $spth = 9;

my $prime_cnt = 2;
my $z = $primes[-1];

while ( $prime_cnt < 10_001 ) {
$z += 2; # skip evens
add_spoke();

my $ix = 1; # skip factors of 2
while ( $ix < $spix ) {
$spokes[$ix] += $primes[$ix]
if ( $spokes[$ix] < $z );

if ( $z == $spokes[$ix] ) {
$z += 2;
add_spoke();
$ix = 1;
}
else {
$ix += 1;
}
}

push(@primes, $z);
++$prime_cnt;
}

sub add_spoke {
if ( $z == $spth ) {
$spokes[$spix] = $spth;
$spix += 1;
$spth = $primes[$spix] ** 2;
}
}

say $primes[-1];
Something went wrong with that request. Please try again.