Earliest difference between prime gaps: Difference between revisions

Content added Content deleted
(Realize in F#)
(Added Sidef)
Line 1,022: Line 1,022:
Gap 386 starts at 35238645587, gap 388 starts at 156798792223, difference is 121560146636.
Gap 386 starts at 35238645587, gap 388 starts at 156798792223, difference is 121560146636.


</pre>

=={{header|Sidef}}==
<lang ruby>func prime_gap_records(upto) {

var gaps = []
var p = 3

each_prime(p.next_prime, upto, {|q|
gaps[q-p] := p
p = q
})

gaps.grep { defined(_) }
}

var gaps = prime_gap_records(1e8)

for m in (1 .. gaps.max.len) {
gaps.each_cons(2, {|p,q|
if (abs(q-p) > 10**m) {
say "10^#{m} -> (#{p}, #{q}) with gaps (#{
p.next_prime-p}, #{q.next_prime-q}) and difference #{abs(q-p)}"
break
}
})
}</lang>
{{out}}
<pre>
10^1 -> (7, 23) with gaps (4, 6) and difference 16
10^2 -> (113, 1831) with gaps (14, 16) and difference 1718
10^3 -> (113, 1831) with gaps (14, 16) and difference 1718
10^4 -> (9551, 30593) with gaps (36, 38) and difference 21042
10^5 -> (173359, 31397) with gaps (70, 72) and difference 141962
10^6 -> (396733, 1444309) with gaps (100, 102) and difference 1047576
10^7 -> (2010733, 13626257) with gaps (148, 150) and difference 11615524
</pre>
</pre>