mirror of
https://github.com/bobbimanners/EightBall.git
synced 2024-10-19 23:23:49 +00:00
f72fcdc253
- Arrays can now be initialized with a list like this: `word aa[4]={1,2,3,4}` ... - ... or a string literal like this: `byte qw[100]="This is a test"` - Works in interpreter or compiled.
51 lines
762 B
Plaintext
51 lines
762 B
Plaintext
' Sieve of Eratosthenes
|
|
|
|
pr.msg "Sieve of Eratosthenes ..."
|
|
|
|
byte A[30*30] = {}
|
|
word i = 0
|
|
for i = 0 : 30*30-1
|
|
A[i] = 1
|
|
endfor
|
|
call doall(30, 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
|
|
|