81 lines
2.4 KiB
COBOL
81 lines
2.4 KiB
COBOL
IDENTIFICATION DIVISION.
|
|
PROGRAM-ID. AOC22D10.
|
|
|
|
ENVIRONMENT DIVISION.
|
|
INPUT-OUTPUT SECTION.
|
|
FILE-CONTROL.
|
|
SELECT INPUT-FILE ASSIGN TO 'input'
|
|
ORGANIZATION IS LINE SEQUENTIAL
|
|
ACCESS IS SEQUENTIAL.
|
|
|
|
DATA DIVISION.
|
|
FILE SECTION.
|
|
FD INPUT-FILE.
|
|
01 INPUT-RECORD PIC A(16).
|
|
|
|
WORKING-STORAGE SECTION.
|
|
01 INSTRUCTION.
|
|
05 INS PIC A(5).
|
|
05 VAL PIC S9(10).
|
|
01 CLOCK PIC 9(10) VALUE 1 USAGE IS COMP.
|
|
01 BUSY PIC 9(10) USAGE IS COMP.
|
|
01 X PIC S9(10) VALUE 1 USAGE IS COMP.
|
|
01 RESULT PIC 9(10) USAGE IS COMP.
|
|
01 RESULT-F PIC Z(10).
|
|
|
|
PROCEDURE DIVISION.
|
|
START-ROUTINE.
|
|
OPEN INPUT INPUT-FILE.
|
|
|
|
DISPLAY 'Gold:'.
|
|
DISPLAY ' ' WITH NO ADVANCING.
|
|
|
|
READ-ROUTINE.
|
|
MOVE SPACES TO INPUT-RECORD.
|
|
MOVE SPACES TO INSTRUCTION.
|
|
READ INPUT-FILE AT END GO TO END-ROUTINE.
|
|
UNSTRING INPUT-RECORD DELIMITED BY SPACE
|
|
INTO INS, VAL.
|
|
|
|
IF INS = 'addx' THEN
|
|
SET BUSY TO 2
|
|
ELSE
|
|
SET BUSY TO 1
|
|
END-IF.
|
|
PERFORM EXECUTION UNTIL BUSY = 0
|
|
|
|
IF INS = 'addx' THEN
|
|
ADD VAL TO X.
|
|
|
|
GO TO READ-ROUTINE.
|
|
|
|
EXECUTION.
|
|
IF FUNCTION REM(CLOCK - 20, 40) = 0 THEN
|
|
COMPUTE RESULT = RESULT + CLOCK * X
|
|
END-IF.
|
|
|
|
IF FUNCTION REM(CLOCK - 1, 40) IS
|
|
GREATER THAN OR EQUAL TO X - 1 AND
|
|
FUNCTION REM(CLOCK - 1, 40) IS
|
|
LESS THAN OR EQUAL TO X + 1 THEN
|
|
DISPLAY '#' WITH NO ADVANCING
|
|
ELSE
|
|
DISPLAY '.' WITH NO ADVANCING
|
|
END-IF.
|
|
|
|
IF FUNCTION REM(CLOCK, 40) EQUALS 0 THEN
|
|
DISPLAY ' '
|
|
DISPLAY ' ' WITH NO ADVANCING
|
|
END-IF.
|
|
|
|
SUBTRACT 1 FROM BUSY.
|
|
ADD 1 TO CLOCK.
|
|
|
|
END-ROUTINE.
|
|
CLOSE INPUT-FILE.
|
|
MOVE RESULT TO RESULT-F.
|
|
DISPLAY ' '.
|
|
DISPLAY 'Silver: 'RESULT-F.
|
|
STOP RUN.
|
|
|
|
END PROGRAM AOC22D10.
|