home *** CD-ROM | disk | FTP | other *** search
/ Big Blue Disk 16 / bbd16.zip / ERAT.SP < prev    next >
Text File  |  1983-10-25  |  2KB  |  70 lines

  1. BEGIN
  2.     COMMENT Sieve of Eratosthenes program to calculate
  3.         prime numbers. ;
  4.  
  5.  
  6.     REAL Time_in_seconds; { Output argument of PROCEDURE
  7.                 Compute_time_in_seconds.        }
  8.  
  9.     PROCEDURE Compute_time_in_seconds;
  10.     BEGIN
  11.         STRING Time_string; { This holds the current time. }
  12.  
  13.         Time_string:=TIME$; { HH:MM:SS }
  14.         Time_in_seconds:=VAL(MID$(Time_string,1,2))*3600 {Hours * 3600}
  15.             +VAL(MID$(Time_string,4,2))*60  {Minutes*60 added}
  16.             +VAL(MID$(Time_string,7,2)); {Seconds added}
  17.  
  18.         { The time in seconds are now computed. }
  19.     END
  20.  
  21.  
  22.     INTEGER ARRAY FLAGS(8191); {Prime number flags.}
  23.  
  24.     INTEGER I,M,K,PRIME,COUNT; {Loop variables,prime number counter.}
  25.  
  26.     REAL Start_time,        {Start time of test}
  27.          Finish_time;       {Finish time for ten iterations.}
  28.  
  29.     Compute_time_in_seconds; {Compute the current time.}
  30.     Start_time:=Time_in_seconds; {Set Start time.}
  31.  
  32.     OUTPUT('Time is:' + TIME$);
  33.  
  34.     FOR M := 1 STEP 1 UNTIL 10 DO
  35.     BEGIN
  36.         COUNT := 0;
  37.  
  38.         FOR I := 1 STEP 1 UNTIL 8191 DO
  39.         BEGIN
  40.             FLAGS(I) := 1;
  41.         END
  42.  
  43.         FOR I := 1 STEP 1 UNTIL 8191 DO
  44.         BEGIN
  45.             IF FLAGS(I) = 1 THEN
  46.             BEGIN
  47.                 PRIME := I+I+3;
  48.                 K := I+PRIME;
  49.  
  50.                 WHILE K <= 8191 DO
  51.                 BEGIN
  52.                     FLAGS(K) := 0;
  53.                     K := K+PRIME;
  54.                 END
  55.  
  56.                 COUNT := COUNT+1;
  57.             END
  58.         END
  59.     END
  60.  
  61.     Compute_time_in_seconds; {Compute the current time.}
  62.     Finish_time:=Time_in_seconds; {Set Finish time.}
  63.  
  64.     OUTPUT('Time is:' + TIME$); OUTPUT();
  65.     OUTPUT(COUNT @ ' PRIMES for each of Ten iterations.'); OUTPUT();
  66.     OUTPUT('Time for one iteration is:' @
  67.          (Finish_time - Start_time)/10.
  68.         @ ' seconds.');
  69. END 
  70.