Data update
This commit is contained in:
parent
81fd053722
commit
52a6ef48dd
10248 changed files with 63654 additions and 6775 deletions
35
Task/Twin-primes/FutureBasic/twin-primes.basic
Normal file
35
Task/Twin-primes/FutureBasic/twin-primes.basic
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
_max = 1000000000
|
||||
_size = _max/16 + 16
|
||||
uint8 primes(_size)
|
||||
|
||||
local fn twins( max as uint64 )
|
||||
CFTimeInterval t : t = fn CACurrentMediaTime
|
||||
uint64 num, p, twins = 0, prev = 0
|
||||
|
||||
for num = 3 to max step 2
|
||||
if primes(num >> 4) & bit((num & 15) >> 1) then continue
|
||||
|
||||
p = num * num
|
||||
while p < max
|
||||
primes(p >> 4) |= bit((p & 15) >> 1)
|
||||
p += num << 1
|
||||
wend
|
||||
|
||||
twins += (num == prev + 2)
|
||||
prev = num
|
||||
next
|
||||
|
||||
printf @"%10d twin primes in first %d integers %.3f ms."¬
|
||||
, twins, max, 1000 * (fn CACurrentMediaTime - t)
|
||||
end fn
|
||||
|
||||
window 1, @"Twin Primes"
|
||||
print
|
||||
CFTimeInterval tm : tm = fn CACurrentMediaTime
|
||||
for byte x = 1 to 9
|
||||
fn memset( @primes(0), 0, _size ) //Clear array for each run
|
||||
fn twins( 10^x )
|
||||
next
|
||||
printf @" Total time: %.3f sec.",(fn CACurrentMediaTime - tm)
|
||||
|
||||
handleevents
|
||||
Loading…
Add table
Add a link
Reference in a new issue