diff options
| author | Trey Bastian <hello@treybastian.com> | 2025-12-01 14:03:23 +0000 |
|---|---|---|
| committer | Trey Bastian <hello@treybastian.com> | 2025-12-01 14:03:23 +0000 |
| commit | 8bedb78899f872f151f2f36dbd97f3194acb64ec (patch) | |
| tree | c67906c633612d503b56186cc758f59b68edb613 | |
| parent | 0880a0dfbb4b71caad75aaae5daf23eb2d2db5d5 (diff) | |
2025 day 1 part 2
| -rw-r--r-- | 2025/day_01_part2.cbl | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/2025/day_01_part2.cbl b/2025/day_01_part2.cbl new file mode 100644 index 0000000..149c3af --- /dev/null +++ b/2025/day_01_part2.cbl @@ -0,0 +1,67 @@ + IDENTIFICATION DIVISION. + PROGRAM-ID. day_01_part2. + AUTHOR. Trey Bastian. + ENVIRONMENT DIVISION. + INPUT-OUTPUT SECTION. + FILE-CONTROL. + SELECT input-file ASSIGN TO "./input.txt" + ORGANIZATION IS LINE SEQUENTIAL. + DATA DIVISION. + FILE SECTION. + FD input-file. + 01 input-line. + 02 direction PIC X. + 02 move-text PIC XXX. + WORKING-STORAGE SECTION. + 01 dial-position PIC 9(2) VALUE 50. + 01 new-position PIC 9(2). + 01 move-num PIC S9(3). + 01 zero-count PIC 9(4) VALUE ZEROS. + 01 eof PIC X. + 88 eof-y VALUE "Y". + 88 eof-n VALUE "N". + + + PROCEDURE DIVISION. + OPEN INPUT input-file. + SET eof-n to TRUE. + PERFORM UNTIL eof-y + READ input-file AT END + SET eof-y to TRUE + NOT AT END + MOVE FUNCTION NUMVAL(move-text) TO move-num + IF move-num > 99 + COMPUTE zero-count = zero-count + (move-num / 100) + END-IF + + IF direction = "L" + COMPUTE move-num = 0 - move-num + END-IF + + COMPUTE new-position = FUNCTION MOD(dial-position + + move-num, 100) + + if new-position < 0 + ADD 100 to new-position + END-IF + + EVALUATE new-position + WHEN 0 + ADD 1 to zero-count + WHEN < dial-position AND direction = "R" AND + dial-position <> 0 + ADD 1 to zero-count + WHEN > dial-position AND direction = "L" AND + dial-position <> 0 + ADD 1 to zero-count + END-EVALUATE + + + MOVE new-position TO dial-position + + END-READ + END-PERFORM. + CLOSE input-file. + DISPLAY zero-count. + STOP-RUN. + |
