Sequence of primorial primes
constant @primes = |grep *.is-prime, 2..*;
constant @primorials = [\*] 1, @primes;
my @pp_indexes := |@primorials.pairs.map: {
.key if ( .value + any(1, -1) ).is-prime
};
say ~ @pp_indexes[ 0 ^.. 20 ]; # Skipping bogus first element.Output:
1 2 3 4 5 6 11 13 24 66 68 75 167 171 172 287 310 352 384 457Alternate implementation
merged from another removed draft task.
my @primorials = 1, |[\*] (2..*).grep: &is-prime;
sub abr ($_) { .chars < 41 ?? $_ !! .substr(0,20) ~ '..' ~ .substr(*-20) ~ " ({.chars} digits)" }
my $limit;
for ^∞ {
my \p = @primorials[$_];
++$limit and printf "%2d: %5s - 1 = %s\n", $limit, "p$_#", abr p -1 if (p -1).is-prime;
++$limit and printf "%2d: %5s + 1 = %s\n", $limit, "p$_#", abr p +1 if (p +1).is-prime;
exit if $limit >= 30
}Output:
PreviousSequence of primes by trial divisionNextSequence smallest number greater than previous term with exactly n divisors
Last updated
Was this helpful?