DataMuseum.dk

Presents historical artifacts from the history of:

Bogika Butler

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about Bogika Butler

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - metrics - download

⟦58d589ca2⟧ TextFile

    Length: 1664 (0x680)
    Types: TextFile
    Names: »PRIMES.PAS«

Derivation

└─⟦314366c8f⟧ Bits:30009789/_.ft.Ibm2.50006598.imd Mogens Pelles Zilog 80,000 / EOS projekt
    └─⟦this⟧ »PRIMES.PAS« 
└─⟦977c9bad1⟧ Bits:30009789/_.ft.Ibm2.50006590.imd Mogens Pelles Zilog 80,000 / EOS projekt
    └─⟦this⟧ »PRIMES.PAS« 

TextFile

PROGRAM primes(input,output);
æComputes primes up to a given limit,  
 using the "sieve of Eratosthenes" å
CONST
  maxnumber = 32767;
  maxhalf = 16383;  æmaxnumber DIV 2å
TYPE
  number = 1..maxnumber;
  half = 1..maxhalf;
VAR
  count,factor,maxfactor,limit,nonprime: number;
  index,halflimit: half;
  primeflags: ARRAY ÆhalfÅ OF boolean;
BEGIN
  REPEAT
    writeln('Upper limit = ?');
    readln(limit);
  UNTIL (1 <= limit) AND (limit <= maxnumber);
  halflimit := pred(limit) DIV 2;
  FOR index := 1 TO halflimit DO primeflagsÆindexÅ := true;
  æIf a number is composite, at least one of its factors is 
   less than or equal to its square root, so: å
  maxfactor := round(sqrt(limit));
  count := 2;  æcount of primes: 1 and 2 are the first twoå
  factor := 1;  æfirst actual factor used will be 3å
  FOR index := 1 TO halflimit DO
    BEGIN
      factor := factor + 2;  æi.e. factor := 2*index + 1å
      IF primeflagsÆindexÅ THEN
        æA new prime has been found å
        BEGIN  count := succ(count);
          æIf necessary, cross out all its multipleså
          IF factor <= maxfactor THEN
            BEGIN  nonprime := index + factor;
              WHILE nonprime <= halflimit DO
                BEGIN
                  primeflagsÆnonprimeÅ := false;
                  nonprime := nonprime + factor;
                END æWHILEå;
            END;
          writeln(factor);      æomitted for timingå
        END æIFå;
    END æFORå;
  writeln('Number of primes up to ',limit,' = ',count);
END.
«eof»