*//////////////////////////////////////////////////////////
*// Name: Peter M. Maurer
*// Program: Sieve of Eratosthenes
*// Due: Never
*// Language: SNOBOL4
*//////////////////////////////////////////////////////////

*          define the sieve data structure
*          everything is potentially prime until proven otherwise
           CANDIDATES = ARRAY('0:1000', 1)
*          Neither 1 nor 0 is prime, so flag them off
           CANDIDATES<0> = 0
           CANDIDATES<1> = 0
*          start the sieve with the integer 0
           I = 0
LOOP1      LT(I,1000)                                 :F(ELOOP1)
*		   advance to the next un-crossed out number.
*		   this number must be a prime
           EQ(CANDIDATES<I>,0)                        :F(ELOOP2)
		   I = I + 1                                  :(LOOP1)
ELOOP2	   J = 2
           K = I * J
LOOP3      LT(K,1000)                                 :F(ELOOP3)
           CANDIDATES<K> = 0
           J = J + 1
           K = I * J                                  :(LOOP3)
*		   advance to the next candidate
ELOOP3     I = I + 1                                  :(LOOP1)
ELOOP1	   I = 0
*          all uncrossed-out numbers are prime (and only those numbers)
*          print all primes
LOOP4      LT(I,1000)                                 :F(ELOOP4)
           NE(CANDIDATES<I>,0)                        :F(SKIP1)
		   OUTPUT = I " is prime"
SKIP1      I = I + 1                                  :(LOOP4)
ELOOP4     I = 0
END
