dos_compilers/Logitech Modula-2 v34/SIEVE.MOD
2024-07-02 07:25:31 -07:00

44 lines
1.1 KiB
Modula-2

(*$S-*)
(*$R-*)
(*$T-*)
(*********************************************************************)
(* The Sieve Benchmark *)
(* *)
(* Compile with test, overflow switches off and native code on. *)
(* *)
(*********************************************************************)
MODULE prime;
FROM InOut IMPORT WriteLn, WriteInt, WriteCard, WriteString;
CONST
size = 8190;
VAR
flags : ARRAY [ 0 .. size ] OF BOOLEAN;
i, prime, k, count, iter : CARDINAL;
ch : CHAR;
BEGIN
WriteString("10 iterations");
FOR iter := 1 TO 10 DO
count := 0;
FOR i := 0 TO size DO flags[i] := TRUE END;
FOR i := 0 TO size DO
IF flags[i] THEN
prime := i + i + 3;
k := i + prime;
WHILE k <= size DO
flags[k] := FALSE;
k := k + prime;
END;
count := count + 1;
END;
END;
END;
WriteCard( count, 5 );
WriteString( " primes" );
WriteLn;
END prime.