Category:Action! Sieve of Eratosthenes: Difference between revisions

From Rosetta Code
Content added Content deleted
(→‎Sieve of Eratosthenes: fixed syntax highlighting)
 
Line 5: Line 5:
The following module marks prime numbers using Sieve of Eratosthenes algorithm.
The following module marks prime numbers using Sieve of Eratosthenes algorithm.


<syntaxhighlight lang="action!">
<lang Action!>MODULE
MODULE


PROC Sieve(BYTE ARRAY primes INT count)
PROC Sieve(BYTE ARRAY primes INT count)
Line 24: Line 25:
RETURN
RETURN


MODULE</lang>
MODULE
</syntaxhighlight>

Latest revision as of 22:55, 27 September 2022

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