Baseline: tree as shared
This commit is contained in:
1679 files changed
+1024562
No files matched your search
@@ -0,0 +1,19 @@
|
||||
// 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)
|
||||
Reference in new issue
Block a user