Jump to content

Earliest difference between prime gaps: Difference between revisions

→‎{{header|Wren}}: Modified to use a segmented sieve.
(→‎{{header|Wren}}: Modified to use a segmented sieve.)
Line 1,005:
{{libheader|Wren-math}}
{{libheader|Wren-fmt}}
Unfortunately,This myuses machinea doesn'tsegmented havesieve enoughto avoid running out of memory towhen looklooking for the earliest difference >above 1 billion. Takes a little over 5½ minutes to run (25 seconds to reach first 100 million) on my machine (core i7, 32GB RAM, Ubuntu 20.04).
 
This takes 23 seconds to run on my machine (core i7, 32GB RAM, Ubuntu 20.04) which is what I'd expect as Wren is typically 4 or 5 times slower than Phix.
 
If anyone's wondering why I can't sieve 5 billion numbers with this much RAM, the reason is that bools require 8 bytes of storage in Wren (all value types do) compared to only 1 byte in most statically typed languages (or even 1 bit if they support bitarrays).
<lang ecmascript>import "./math" for Int
import "/fmt" for Fmt
 
var limit = 1e81e9
var gapStarts = {}
var primes = Int.primeSievesegmentedSieve(limit * 45, 8 * 1024 * 1024) // 8 MB cache
for (i in 1...primes.count) {
var gap = primes[i] - primes[i-1]
Line 1,067 ⟶ 1,063:
Earliest difference > 100,000,000 between adjacent prime gap starting primes:
Gap 198 starts at 46,006,769, gap 200 starts at 378,043,979, difference is 332,037,210.
 
Earliest difference > 1,000,000,000 between adjacent prime gap starting primes:
Gap 276 starts at 649,580,171, gap 278 starts at 4,260,928,601, difference is 3,611,348,430.
</pre>
9,482

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.