//ALGOL601 JOB //JOBLIB DD DSN=SYS1.ALGLIB,DISP=SHR //SALGOL EXEC ALGOFCLG //ALGOL.SYSIN DD * begin comment ////////////////////////////////////////////////////////// // NAME: PETER M. MAURER // PROGRAM: SIEVE OF ERATOSTHENES // DUE: NEVER // LANGUAGE: ALGOL 60 ALA IBM 360 // http://cs.ecs.baylor.edu/~maurer/SieveE/Algol360.htm ////////////////////////////////////////////////////////// ; comment DEFINE THE SIEVE DATA STRUCTURE ; integer array CANDIDATES(/0..1000/); integer I,J,K; comment SET LINE-LENGTH=120,SET LINES-PER-PAGE=62,OPEN SYSACT(1,6,120); SYSACT(1,8,62); SYSACT(1,12,1); comment 1000 TO PROTECT AGAINST STRICT EVALUATION OF AND ; for I := 0 step 1 until 1000 do begin comment EVERYTHING IS POTENTIALLY PRIME UNTIL PROVEN OTHERWISE ; CANDIDATES(/I/) := 1; end; comment NEITHER 1 NOR 0 IS PRIME, SO FLAG THEM OFF ; CANDIDATES(/0/) := 0; CANDIDATES(/1/) := 0; comment START THE SIEVE WITH THE INTEGER 0 ; I := 0; for I := I while I less 1000 do begin comment ADVANCE TO THE NEXT UN-CROSSED OUT. ; comment THIS NUMBER MUST BE A PRIME; for I := I while I less 1000 and CANDIDATES(/I/) equal 0 do begin I := I+1; end; comment INSURE AGAINST RUNNING OFF THE END; if I less 1000 then begin comment CROSS OUT ALL MULTIPLES OF THE PRIME.; J := 2; K := J*I; for K := K while K less 1000 do begin CANDIDATES(/K/) := 0; J := J + 1; K := J*I; end; comment ADVANCE TO THE NEXT CANDIDATE ; I := I+1; end end; comment ALL UNCROSSED OUT NUMBERS ARE PRIME; comment PRINT ALL PRIMES ; for I := 0 step 1 until 999 do begin if CANDIDATES(/I/) notequal 0 then begin OUTINTEGER(1,I); OUTSTRING(1,'(' IS PRIME')'); SYSACT(1,14,1) end end end /* //GO.ALGLDD01 DD DSN=&&DD01,UNIT=SYSDA,DISP=(,PASS),SPACE=(CYL,20), 00200000 // DCB=(RECFM=FBA,LRECL=121,BLKSIZE=605) 00210000 //GO.SYSPRINT DD DSN=&&SYSP,UNIT=SYSDA,DISP=(,PASS),SPACE=(CYL,20), 00220000 // DCB=(RECFM=FBA,LRECL=121,BLKSIZE=605) 00230000 //PTPCH01 EXEC PGM=IEBPTPCH,COND=(0,NE,SALGOL.GO) 00240000 //SYSPRINT DD DUMMY 00250000 //SYSIN DD * 00260000 PRINT PREFORM=A 00270000 /* 00280000 //SYSUT1 DD DSN=&&SYSP,DISP=(OLD,PASS) 00290000 //SYSUT2 DD SYSOUT=A 00300000 //PTPCH02 EXEC PGM=IEBPTPCH,COND=(0,NE,SALGOL.GO) 00310000 //SYSPRINT DD DUMMY 00320000 //SYSIN DD * 00330000 PRINT PREFORM=A 00340000 /* 00350000 //SYSUT1 DD DSN=&&DD01,DISP=(OLD,PASS) 00360000 //SYSUT2 DD SYSOUT=A 00370000 //