Category:Action! Sieve of Eratosthenes

Sieve of Eratosthenes

SIEVE.ACT

The following module marks prime numbers using Sieve of Eratosthenes algorithm.

MODULE

PROC Sieve(BYTE ARRAY primes INT count)
  CARD i,j

  SetBlock(primes,count,1)
  primes(0)=0 primes(1)=0 i=2
  WHILE i<count
  DO
    IF primes(i)=1 THEN
      FOR j=2*i TO count-1 STEP i
      DO
        primes(j)=0
      OD
    FI
    i==+1
  OD
RETURN

MODULE