//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 ////////////////////////////////////////////////////////// ; '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 //