home · login to get plonkin'

aoc24-d2p1 in cobol

@oppi.li · 27d ago · plaintext · 91 loc · raw · 1 comment

1       IDENTIFICATION DIVISION.2       PROGRAM-ID. D2.34       ENVIRONMENT DIVISION.5       INPUT-OUTPUT SECTION.6       FILE-CONTROL.7           SELECT INPUT-FILE ASSIGN TO "IN/2.TXT"8               ORGANIZATION IS LINE SEQUENTIAL.910       DATA DIVISION.11       FILE SECTION.12       FD INPUT-FILE.13       01 INPUT-LINE PIC X(25).1415       WORKING-STORAGE SECTION.16       01 EOF            PIC X    VALUE 'N'.17       01 SAFE-COUNT     PIC 9(5) VALUE 0  .18       01 DIFF           PIC S9(5)         .19       01 IDX            PIC 9(5)          .20       01 PTR            PIC 9(5) VALUE 1  .2122       01 NOS OCCURS 8 TIMES.23           05 ELT        PIC X(2) VALUE ' '.2425       01 OLD-SLOPE      PIC X    VALUE ' '.26       01 SLOPE          PIC X    VALUE ' '.27       01 SAFETY         PIC X             .28           88 SAFE                VALUE 'Y'.29           88 UNSAFE              VALUE 'N'.303132       PROCEDURE DIVISION.33           OPEN INPUT INPUT-FILE.34           PERFORM PART-1 UNTIL EOF = "Y".35           DISPLAY SAFE-COUNT.36           CLOSE INPUT-FILE.37           STOP RUN.3839       PART-1.40           READ INPUT-FILE41               AT END MOVE "Y" TO EOF42               NOT AT END43                   PERFORM PARSE-LINE44                   PERFORM SAFE-CHECK45           END-READ.4647       PARSE-LINE.48           MOVE 1 TO PTR.49           PERFORM VARYING IDX FROM 1 BY 1 UNTIL PTR =50               LENGTH INPUT-LINE51               UNSTRING INPUT-LINE DELIMITED BY SPACES52                   INTO ELT(IDX) WITH POINTER PTR53           END-PERFORM.5455       SAFE-CHECK.56           MOVE ' ' TO OLD-SLOPE SLOPE.57           SET SAFE TO TRUE.5859           PERFORM VARYING IDX FROM 2 BY 160               UNTIL UNSAFE OR ELT(IDX) = SPACE OR IDX > 86162               PERFORM CALC-DIFF-SLOPE63               PERFORM SAFETY-COND6465               MOVE SLOPE TO OLD-SLOPE6667           END-PERFORM.68           DISPLAY INPUT-LINE ' ' SAFETY69           IF SAFE70               ADD 1 TO SAFE-COUNT71           END-IF.7273       CALC-DIFF-SLOPE.74           COMPUTE DIFF = FUNCTION NUMVAL(ELT(IDX)) - FUNCTION75               NUMVAL(ELT(IDX - 1)).76           IF DIFF < 077               MOVE 'N' TO SLOPE78           ELSE79               MOVE 'P' TO SLOPE80           END-IF.8182       SAFETY-COND.83           IF OLD-SLOPE NOT= SPACE AND OLD-SLOPE NOT= SLOPE84               SET UNSAFE TO TRUE85           END-IF.8687           IF FUNCTION ABS(DIFF) < 1 OR FUNCTION ABS(DIFF) > 388               SET UNSAFE TO TRUE89           END-IF.9091

comments

@oppi.li · 27d ago

on the sample input:

    λ cobc -x -j d2.cbl

    7 6 4 2 1                 Y
    1 2 7 8 9                 N
    9 7 6 2 1                 N
    1 3 2 4 5                 N
    8 6 4 4 1                 N
    1 3 6 7 9                 Y
    00002

login to post a comment