Files
pplus-web/tests/corpus/05-primes-sieve.pseudo
T
2026-10-05 03:03:38 +00:00

20 lines
570 B
Plaintext

// An ARRAY of BOOL, nested loops with STEP, and a LIST answer.
// EXPECT: [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
FUNCTION PRIMES_UP_TO(N : INTEGER) RETURNS LIST OF INTEGER
DECLARE IsPrime : ARRAY[N + 1] OF BOOL
DECLARE Found : LIST OF INTEGER
FOR I <- 0 TO N + 1
IsPrime[I] <- I >= 2
NEXT I
FOR I <- 2 TO N + 1
IF IsPrime[I] THEN
APPEND(Found, I)
FOR J <- I * I TO N + 1 STEP I
IsPrime[J] <- FALSE
NEXT J
ENDIF
NEXT I
RETURN Found
ENDFUNCTION
OUTPUT PRIMES_UP_TO(30)