home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 2 / crawlyvol2.bin / program / pascal / passrc / sieve1.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1985-11-18  |  2.5 KB  |  80 lines

  1. { -----------------------------------------------------------------------------
  2.  
  3.                                  NOTICE:
  4.  
  5.       THESE MATERIALS are UNSUPPORTED by OSS!  If you do not understand how to
  6.       use them do not contact OSS for help!  We will not teach you how to 
  7.       program in Pascal.  If you find an error in these materials, feel free
  8.       to SEND US A LETTER explaining the error, and how to fix it.
  9.  
  10.       THE BOTTOM LINE:
  11.  
  12.          Use it, enjoy it, but you are on your own when using these materials!
  13.  
  14.  
  15.                                DISCLAIMER:
  16.  
  17.       OSS makes no representations or warranties with respect to the contents
  18.       hereof and specifically disclaim all warranties of merchantability or
  19.       fitness for any particular purpose.   This document is subject to change
  20.       without notice.
  21.       
  22.       OSS provides these materials for use with Personal Pascal.  Use them in
  23.       any way you wish.
  24.  
  25.    -------------------------------------------------------------------------- }
  26.  
  27.  
  28. (* Erastosthenes Sieve Prime Number Program *)
  29. (* Tests integer math *)
  30.  
  31. program prime;
  32. const
  33.   size = 8190;
  34. TYPE
  35.   lint_pointer = ^long_integer;
  36. var
  37.   flags : packed array [0..size] of boolean;
  38.   i,prime,k,count,iter : integer;
  39.   funny: RECORD
  40.            CASE boolean OF
  41.              true:  ( l: long_integer );
  42.              false: ( p: lint_pointer );
  43.          END;
  44.   start_time, end_time: long_integer;
  45.   ssp: long_integer;
  46.  
  47.   FUNCTION super( sp: long_integer ): long_integer;
  48.     GEMDOS($20);
  49.  
  50. begin
  51.   ssp := super(0);
  52.   writeln('10 iterations');
  53.   funny.l := $4ba;
  54.   start_time := funny.p^;
  55.   for iter := 1 to 10 do begin
  56.         count := 0;
  57.         for i := 0 to size do
  58.                 flags[i] := true;
  59.         for i := 0 to size do
  60.                 if flags[i] then begin
  61.                         prime := i+i+3;
  62.                         {writeln(prime);}
  63.                         k := i+prime;
  64.                         while k <= size do begin
  65.                                 flags[k] := false;
  66.                                 k := k + prime
  67.                         end;
  68.                         count := count + 1
  69.                 end;
  70.   end;
  71.   end_time := funny.p^;
  72.   writeln(count,' primes.');
  73.   writeln( ((end_time-start_time)/200):5:2, ' seconds' );
  74.   ssp := super(ssp);
  75. end.
  76.  
  77. { Runs in approx 6.1 sec. on Atari ST (Personal Pascal). }
  78. { Runs in 5.38 sec. on IBM PC AT @ 6 MHz. (Turbo Pascal). }
  79. { Runs in 3.95 sec. on IBM PC AT @ 8 MHz. (Turbo Pascal). }
  80.