home · login to get plonkin'

aoc24-d1p1 in cobol

@oppi.li · 1mo ago · plaintext · 63 loc · raw · 2 comments

1       IDENTIFICATION DIVISION.2       PROGRAM-ID. D1.34       ENVIRONMENT DIVISION.5       INPUT-OUTPUT SECTION.6       FILE-CONTROL.7           SELECT INPUT-FILE ASSIGN TO "INPUT1.TXT"8               ORGANIZATION IS LINE SEQUENTIAL.910       DATA DIVISION.11       FILE SECTION.12       FD INPUT-FILE.13       01 INPUT-LINE.14         05 LEFT-NO  PIC 9(5).15         05 FILLER   PIC X(3).16         05 RIGHT-NO PIC 9(5).1718       WORKING-STORAGE SECTION.19       01 LEFT-NOS OCCURS 1000 INDEXED BY LEFT-IDX.20           05 LEFT-NO-ELT PIC 9(5).21       01 RIGHT-NOS OCCURS 1000 INDEXED BY RIGHT-IDX.22           05 RIGHT-NO-ELT PIC 9(5).23       01 IDX PIC 9(5).24       01 ANSWER PIC 9(9).25       01 EOF PIC X VALUE "N".2627       PROCEDURE DIVISION.28           OPEN INPUT INPUT-FILE.29           PERFORM READ-LINE UNTIL EOF = "Y".30           PERFORM SORT-TABLES.31           PERFORM PART-1.32           DISPLAY ANSWER.33           CLOSE INPUT-FILE.34           STOP RUN.3536       READ-LINE.37           READ INPUT-FILE38               AT END MOVE "Y" TO EOF39               NOT AT END PERFORM PARSE-LINE40           END-READ.4142       PARSE-LINE.43           MOVE LEFT-NO TO LEFT-NOS(LEFT-IDX).44           MOVE RIGHT-NO TO RIGHT-NOS(RIGHT-IDX).45           ADD 1 TO LEFT-IDX RIGHT-IDX.4647       SORT-TABLES.48           SORT LEFT-NOS ON ASCENDING KEY LEFT-NO-ELT.49           SORT RIGHT-NOS ON ASCENDING KEY RIGHT-NO-ELT.5051       PART-1.52           PERFORM VARYING IDX FROM 1 BY 1 UNTIL IDX > 100053               COMPUTE ANSWER =54                   ANSWER +55                   FUNCTION ABS(LEFT-NO-ELT(IDX) - RIGHT-NO-ELT(IDX))56               END-PERFORM.5758       DBG-TBLS.59           PERFORM VARYING IDX FROM 1 BY 1 UNTIL IDX > 100060               DISPLAY 'LEFT: ' LEFT-NOS(IDX) ', RIGHT: ' RIGHT-NOS(IDX)61           END-PERFORM.6263

comments

@oppi.li · 1mo ago

compile & run with gnucobol:

    cobc -x -j d1.cbl

login to post a comment