home *** CD-ROM | disk | FTP | other *** search
- { -----------------------------------------------------------------------------
-
- NOTICE:
-
- THESE MATERIALS are UNSUPPORTED by OSS! If you do not understand how to
- use them do not contact OSS for help! We will not teach you how to
- program in Pascal. If you find an error in these materials, feel free
- to SEND US A LETTER explaining the error, and how to fix it.
-
- THE BOTTOM LINE:
-
- Use it, enjoy it, but you are on your own when using these materials!
-
-
- DISCLAIMER:
-
- OSS makes no representations or warranties with respect to the contents
- hereof and specifically disclaim all warranties of merchantability or
- fitness for any particular purpose. This document is subject to change
- without notice.
-
- OSS provides these materials for use with Personal Pascal. Use them in
- any way you wish.
-
- -------------------------------------------------------------------------- }
-
-
- (* Erastosthenes Sieve Prime Number Program *)
- (* Tests integer math *)
-
- program prime;
- const
- size = 8190;
- TYPE
- lint_pointer = ^long_integer;
- var
- flags : packed array [0..size] of boolean;
- i,prime,k,count,iter : integer;
- funny: RECORD
- CASE boolean OF
- true: ( l: long_integer );
- false: ( p: lint_pointer );
- END;
- start_time, end_time: long_integer;
- ssp: long_integer;
-
- FUNCTION super( sp: long_integer ): long_integer;
- GEMDOS($20);
-
- begin
- ssp := super(0);
- writeln('10 iterations');
- funny.l := $4ba;
- start_time := funny.p^;
- for iter := 1 to 10 do begin
- count := 0;
- for i := 0 to size do
- flags[i] := true;
- for i := 0 to size do
- if flags[i] then begin
- prime := i+i+3;
- {writeln(prime);}
- k := i+prime;
- while k <= size do begin
- flags[k] := false;
- k := k + prime
- end;
- count := count + 1
- end;
- end;
- end_time := funny.p^;
- writeln(count,' primes.');
- writeln( ((end_time-start_time)/200):5:2, ' seconds' );
- ssp := super(ssp);
- end.
-
- { Runs in approx 6.1 sec. on Atari ST (Personal Pascal). }
- { Runs in 5.38 sec. on IBM PC AT @ 6 MHz. (Turbo Pascal). }
- { Runs in 3.95 sec. on IBM PC AT @ 8 MHz. (Turbo Pascal). }
-