mirror of
https://github.com/bobbimanners/EightBall.git
synced 2024-10-19 23:23:49 +00:00
18942a9ba0
- Managed to free up several hundred bytes
53 lines
792 B
Plaintext
53 lines
792 B
Plaintext
' Sieve of Eratosthenes
|
|
|
|
pr.msg "Sieve of Eratosthenes ..."
|
|
|
|
const sz=30
|
|
const arrsz=sz*sz
|
|
byte A[arrsz] = {}
|
|
word i = 0
|
|
for i = 0 : arrsz-1
|
|
A[i] = 1
|
|
endfor
|
|
call doall(sz, A)
|
|
end
|
|
|
|
sub doall(word nr, byte array[])
|
|
word n = nr * nr
|
|
pr.msg "nr is "; pr.dec nr; pr.nl
|
|
call sieve(n, nr, array)
|
|
call printresults(n, array)
|
|
return 0
|
|
endsub
|
|
|
|
sub sieve(word n, word nr, byte AA[])
|
|
pr.msg "Sieve"
|
|
word i = 0; word j = 0
|
|
for i = 2 : (nr - 1)
|
|
if AA[i]
|
|
j = i * i
|
|
while (j < n)
|
|
AA[j] = 0
|
|
j = j + i
|
|
endwhile
|
|
endif
|
|
endfor
|
|
return 0
|
|
endsub
|
|
|
|
sub printresults(word n, byte AA[])
|
|
word i = 0
|
|
for i = 2 : (n - 1)
|
|
if AA[i]
|
|
if i > 2
|
|
pr.msg ", "
|
|
endif
|
|
pr.dec i
|
|
endif
|
|
endfor
|
|
pr.msg "."
|
|
pr.nl
|
|
return 0
|
|
endsub
|
|
|