; Sieve of Erastosthenes
; Demo program for ATALAN programming language
;(c) 2010 Rudla Kudla

  
use atari

RTCLOCK@20:byte

const SQRT_COUNT = 91

top:0..8191
sieve:array(top) of 0..1
k,j,prime:top
start,time:byte

"Computing primes..."

for k 
	sieve(k) = 1

RTCLOCK = 0

for i:2..SQRT_COUNT where sieve(i) = 1
		j = i * 2
		while j<=8191
			sieve(j) = 0
			j = j + i

time = RTCLOCK
 
"Time used: [time] ticks"
"Press Q to quit, any other key for list"

CH = none
until CH <> none

for k where sieve(k) = 1 until CH = Q
	 "[k]"
	
CH = none
