public
anonymous / euler47.p6
Created

Perl 6 Project Euler 47

  • Download Gist
euler47.p6
Perl6
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
constant $N = 3;
 
my @primes;
 
my $in-a-row = 0;
 
for 2 .. * {
my $count = 0;
for @primes -> $prime {
if ($prime.key == $_) {
$prime.key += $prime.value;
++$count;
}
}
if ($count >= $N) {
++$in-a-row;
}
else {
if ($count == 0) {
@primes.push($_*2 => $_);
}
$in-a-row = 0;
}
if ($in-a-row == $N) {
say $_ - $N + 1;
last;
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.