Created
December 12, 2020 10:04
-
-
Save jvkersch/7afdbc4ce190eee44610e6ed66043721 to your computer and use it in GitHub Desktop.
Advent of Code 2020, problem 1.1 in Cobol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
IDENTIFICATION DIVISION. | |
PROGRAM-ID. AOC1. | |
ENVIRONMENT DIVISION. | |
INPUT-OUTPUT SECTION. | |
FILE-CONTROL. | |
SELECT INPUTFILE ASSIGN TO 'input' | |
ORGANIZATION IS LINE SEQUENTIAL. | |
DATA DIVISION. | |
FILE SECTION. | |
FD INPUTFILE. | |
01 DIGIT PIC 9(4). | |
WORKING-STORAGE SECTION. | |
01 WS-DIGIT PIC 9(4). | |
01 WS-EOF PIC A(1). | |
01 WS-TABLE. | |
05 WS-A PIC A(1) OCCURS 2020 TIMES VALUE 'N'. | |
01 WS-OUTCOME PIC 9(8). | |
01 WS-OTHER PIC 9(4). | |
PROCEDURE DIVISION. | |
OPEN INPUT INPUTFILE. | |
PERFORM UNTIL WS-EOF='Y' | |
READ INPUTFILE INTO WS-DIGIT | |
AT END MOVE 'Y' TO WS-EOF | |
NOT AT END PERFORM PROCESS-NUMBER | |
END-READ | |
END-PERFORM. | |
CLOSE INPUTFILE. | |
STOP RUN. | |
PROCESS-NUMBER. | |
MOVE 'Y' TO WS-A(WS-DIGIT). | |
SUBTRACT WS-DIGIT FROM 2020 GIVING WS-OTHER. | |
IF WS-A(WS-OTHER)='Y' | |
MULTIPLY WS-DIGIT BY WS-OTHER GIVING WS-OUTCOME | |
DISPLAY WS-OUTCOME | |
END-IF. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment