Earliest difference between prime gaps: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (clarify, absolute value of difference. Thanks to PureFox++ for pointing that out) |
Thundergnat (talk | contribs) m (→{{header|Raku}}: remove leftover no-longer used variable) |
||
Line 83: | Line 83: | ||
my $m = exp $_, 10; |
my $m = exp $_, 10; |
||
my $this; |
my $this; |
||
my $found; |
|||
loop { |
loop { |
||
$this = (my $p = $iterator.next) - $last; |
$this = (my $p = $iterator.next) - $last; |
||
Line 98: | Line 97: | ||
my %upto = @p[^$this].pairs.grep: *.value; |
my %upto = @p[^$this].pairs.grep: *.value; |
||
my @upto = (1..$this).map: { last unless %upto{$_ * 2}; %upto{$_ * 2} } |
my @upto = (1..$this).map: { last unless %upto{$_ * 2}; %upto{$_ * 2} } |
||
my $key = @upto.rotor(2=>-1).first( {.sink; abs(.[0] - .[1]) > $n}, :k); |
my $key = @upto.rotor(2=>-1).first( {.sink; abs(.[0] - .[1]) > $n}, :k ); |
||
return False unless $key; |
return False unless $key; |
||
say "Earliest difference > {comma $n} between adjacent prime gap starting primes:"; |
say "Earliest difference > {comma $n} between adjacent prime gap starting primes:"; |
||
printf "Gap %s starts at %s, gap %s starts at %s, difference is %s\n\n", |
printf "Gap %s starts at %s, gap %s starts at %s, difference is %s\n\n", |
||
|(2 * $key + 2, @upto[$key], 2 * $key + 4, @upto[$key+1], abs( |
|(2 * $key + 2, @upto[$key], 2 * $key + 4, @upto[$key+1], abs(@upto[$key] - @upto[$key+1]))»., |
||
True |
True |
||
}</lang> |
}</lang> |