home *** CD-ROM | disk | FTP | other *** search
/ AMIGA PD 1 / AMIGA-PD-1.iso / Programme_zum_Heft / Programmieren / Kurztests / PascalPCQ / Examples / Sieve.p < prev    next >
Text File  |  1991-03-27  |  717b  |  38 lines

  1. Program Sieve;
  2.  
  3. {
  4.     This is the same old sieve program.  According to the docs for
  5.     Sozobon-C, Manx C runs this in about 7 seconds, and ZC takes about
  6.     five.  PCQ takes about 15 seconds.
  7. }
  8.  
  9. const
  10.     Size = 8190;
  11.     SizePL = Size + 1;
  12.  
  13. Var
  14.     Flags : Array [0..SizePL] of Boolean;
  15.     i, prime,
  16.     k, count,
  17.     iter  : Integer;
  18. begin
  19.     Writeln('10 iterations');
  20.     for iter := 1 to 10 do begin
  21.     count := 0;
  22.     for i := 0 to Size do
  23.         flags[i] := true;
  24.     for i := 0 to Size do begin
  25.         if flags[i] then begin
  26.         prime := i+i+3;
  27.         k := i + prime;
  28.         while k <= size do begin
  29.             flags[k] := false;
  30.             k := k + prime;
  31.         end;
  32.         Inc(count);
  33.         end;
  34.     end;
  35.     end;
  36.     Writeln(Count, ' primes');
  37. end.
  38.