dos_compilers/Microsoft Pascal v1/PRIMES.PAS
2024-06-30 06:59:54 -07:00

32 lines
731 B
Plaintext
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

(* Eratosthenes Sieve Prime Number Program in Pascal *)
(* From September, 1981 Byte magazine, page 182 *)
PROGRAM PRIME (OUTPUT); (*$DEBUG- added, of course *)
CONST
SIZE = 8190;
VAR
FLAGS : ARRAY [0..SIZE] OF BOOLEAN;
I,PRIME,K,COUNT,ITER : INTEGER;
PROCEDURE FILLC(LOC: ADRMEM; LEN: WORD; VAL: CHAR); EXTERN;
BEGIN
WRITELN ('10 iterations');
FOR ITER := 1 TO 10 DO BEGIN
COUNT := 0;
FILLC(ADR FLAGS,SIZEOF(FLAGS),CHR(TRUE));
FOR I := 0 TO SIZE DO
IF FLAGS[I] THEN BEGIN
PRIME := I+I+3;
K := I + PRIME;
WHILE K <= SIZE DO BEGIN
FLAGS[K] := FALSE;
K := K + PRIME
END;
COUNT := COUNT + 1
(* WRITELN(PRIME) *)
END;
END;
WRITELN(COUNT,' primes')
END.