#Day 1 solution on the mainframe

1 messages · Page 1 of 1 (latest)

frosty blaze
#

Putting in thread because 2 sets of codes

#

JCL:

//NRSD225C JOB NRSD225C,
//            '&OADOWNER',
//            CLASS=S,
//            LINES=(999,WARNING),
//            MSGCLASS=R,
//            TIME=1440
//JOBLIB   DD DSN=ISDD0.BATCHUT.LOADLIB,
//            DISP=SHR
//         DD DSN=SYS1.SCEERUN,
//            DISP=SHR
//         DD DSN=SYS1.DSNDND1.SDSNLOAD,
//            DISP=SHR
//         DD DSN=SYS1.DSNDND1.SDSNLOD2,
//            DISP=SHR
//         DD DSN=NDRD0.NRSD225.PHASELIB,
//            DISP=SHR
//         DD DSN=NDRD0.NRSD225.LOADLIB,
//            DISP=SHR
//*-------------------------------------------------------------------*
//*        STEP 0: DELETE OLD FILES
//*-------------------------------------------------------------------*
//D01      EXEC PGM=IEFBR14
//DEL01    DD DSN=NDRD0.NRSD225.AOC.DAY1L,
//            DISP=(OLD,DELETE,DELETE)
//DEL02    DD DSN=NDRD0.NRSD225.AOC.DAY1R,
//            DISP=(OLD,DELETE,DELETE)
//*-------------------------------------------------------------------*
//*        STEP 1: EXTRACT AND SORT LEFT LIST
//*-------------------------------------------------------------------*
//P10      EXEC PGM=SORT
//SYSUDUMP DD SYSOUT=*
//SYSOUT   DD SYSOUT=*
//SORTIN   DD DSN=NDRD0.NRSD225.AOC.DAY1,
//            DISP=SHR
//SYSIN    DD *
  SORT FIELDS=(1,5,CH,A)
  OUTREC FIELDS=(1,5)
//SORTOUT  DD DSN=NDRD0.NRSD225.AOC.DAY1L,
//            DISP=(NEW,CATLG,DELETE),
//            UNIT=PERM,
//            SPACE=(TRK,(2,1),RLSE),
//            DCB=(RECFM=FB,LRECL=5,BLKSIZE=0)
//*-------------------------------------------------------------------*
//*        STEP 2: EXTRACT AND SORT RIGHT LIST
//*-------------------------------------------------------------------*
//P20      EXEC PGM=SORT
//SYSUDUMP DD SYSOUT=*
//SYSOUT   DD SYSOUT=*
//SORTIN   DD DSN=NDRD0.NRSD225.AOC.DAY1,
//            DISP=SHR
//SYSIN    DD *
  SORT FIELDS=(9,5,CH,A)
  OUTREC FIELDS=(9,5)
//SORTOUT  DD DSN=NDRD0.NRSD225.AOC.DAY1R,
//            DISP=(NEW,CATLG,DELETE),
//            UNIT=PERM,
//            SPACE=(TRK,(2,1),RLSE),
//            DCB=(RECFM=FB,LRECL=5,BLKSIZE=0)
//*-------------------------------------------------------------------*
//*        STEP 3: RUN COBOL SOLUTION
//*-------------------------------------------------------------------*
//P30      EXEC PGM=DAY1
//SYSUDUMP DD SYSOUT=*
//ABENDAID DD SYSOUT=*
//SYSOUT   DD SYSOUT=*
//DAY1LIN  DD DSN=NDRD0.NRSD225.AOC.DAY1L,
//            DISP=SHR
//DAY1RIN  DD DSN=NDRD0.NRSD225.AOC.DAY1R,
//            DISP=SHR
#

COBOL

IDENTIFICATION DIVISION.
PROGRAM-ID.   DAY1.
AUTHOR.       Bobby.
DATE-WRITTEN. 02/12/24.

ENVIRONMENT DIVISION.

INPUT-OUTPUT SECTION.

FILE-CONTROL.
    SELECT FILELIN ASSIGN TO DAY1LIN
    FILE STATUS IS WS-INPUT-STATUS.

    SELECT FILERIN ASSIGN TO DAY1RIN
    FILE STATUS IS WS-INPUT-STATUS.

DATA DIVISION.

FILE SECTION.

FD FILELIN
    BLOCK CONTAINS 1000 RECORDS
    RECORDING MODE IS F
    RECORD CONTAINS 5 CHARACTERS.
01 FILELIN-RECORD.
    05 LEFT-NUM                       PIC 9(5).

FD FILERIN
    BLOCK CONTAINS 1000 RECORDS
    RECORDING MODE IS F
    RECORD CONTAINS 5 CHARACTERS.
01 FILELIN-RECORD.
    05 RIGHT-NUM                      PIC 9(5).

WORKING-STORAGE SECTION.

01 WS-INPUT-STATUS                    PIC X(2).
    88 INPUT-OK                       VALUE "00".
    88 INPUT-EOF                      VALUE "10".
    88 INPUT-VALID                    VALUE "00", "10".
01 WS-EOF-POINT                       PIC X VALUE 'N'.
01 WS-L-COUNT-RECORDS                 PIC 9(5) VALUE 0.
01 WS-R-COUNT-RECORDS                 PIC 9(5) VALUE 0.
01 WS-TOTAL-DISTANCE                  PIC 9(9) VALUE 0.
01 WS-LEFT-LIST.
    05 WS-LEFT-NUM                    PIC 9(5) OCCURS 1001 TIMES.
01 WS-RIGHT-LIST.
    05 WS-RIGHT-NUM                   PIC 9(5) OCCURS 1001 TIMES.
01 WS-COUNTER                         PIC 9(5) VALUE 0.
01 WS-L                               PIC 9(5) VALUE 0.
01 WS-R                               PIC 9(5) VALUE 0.
01 WS-SIM-SCORE                       PIC 9(9) VALUE 0.
01 WS-TEMP                            PIC 9(9) VALUE 0.
01 WS-TEMP2                           PIC 9(9) VALUE 0.
01 WS-DIFFERENCE                      PIC S9(5) VALUE 0.
01 WS-DIFFERENCE-ABS                  PIC 9(5) VALUE 0.
#
PROCEDURE DIVISION.

       PROGRAM-CONTROL.
           OPEN INPUT FILELIN.
           PERFORM READ-LEFT-DATA UNTIL WS-EOF-POINT = 'Y'.
           CLOSE FILELIN.

           MOVE 'N' TO WS-EOF-POINT.

           OPEN INPUT FILERIN.
           PERFORM READ-RIGHT-DATA UNTIL WS-EOF-POINT = 'Y'.
           CLOSE FILERIN.

           DISPLAY 'LEFT RECORDS COUNT: ' WS-L-COUNT-RECORDS.
           DISPLAY 'RIGHT RECORDS COUNT: ' WS-R-COUNT-RECORDS.

           PERFORM PART-A.

           PERFORM PART-B.

           STOP RUN.

       READ-LEFT-DATA.
           READ FILELIN AT END MOVE 'Y' TO WS-EOF-POINT.
           ADD 1 TO WS-L-COUNT-RECORDS.
           MOVE LEFT-NUM TO WS-LEFT-NUM(WS-L-COUNT-RECORDS).

       READ-RIGHT-DATA.
           READ FILERIN AT END MOVE 'Y' TO WS-EOF-POINT.
           ADD 1 TO WS-R-COUNT-RECORDS.
           MOVE RIGHT-NUM TO WS-RIGHT-NUM(WS-R-COUNT-RECORDS).

       PART-A.
           PERFORM TRAVERSE-LISTS VARYING WS-COUNTER FROM 1 BY 1
              UNTIL WS-COUNTER > 1000.

           DISPLAY 'TOTAL DISTANCE: ' WS-TOTAL-DISTANCE.

       TRAVERSE-LISTS.
           SUBTRACT WS-LEFT-NUM(WS-COUNTER)
           FROM WS-RIGHT-NUM(WS-COUNTER)
           GIVING WS-DIFFERENCE.

           IF (WS-DIFFERENCE > 0) THEN
              ADD WS-DIFFERENCE TO WS-TOTAL-DISTANCE 
           ELSE
              COMPUTE WS-DIFFERENCE-ABS = WS-DIFFERENCE * (-1)
              ADD WS-DIFFERENCE-ABS TO WS-TOTAL-DISTANCE
           END-IF. 

       PART-B.
           PERFORM VARYING WS-L FROM 1 BY 1 UNTIL WS-L > 1000
              MOVE 0 TO WS-TEMP
              PERFORM VARYING WS-R FROM 1 BY 1 UNTIL WS-R > 1000
                 IF WS-LEFT-NUM(WS-L) = WS-RIGHT-NUM(WS-R)
                    ADD 1 TO WS-TEMP
                 END-IF
              END-PERFORM
              MULTIPLY WS-LEFT-NUM(WS-L) BY WS-TEMP GIVING WS-TEMP2 
              ADD WS-TEMP2 TO WS-SIM-SCORE
           END-PERFORM.

           DISPLAY 'SIMILARITY SCORE: ' WS-SIM-SCORE.
slate pollen
#

this looks very cool but I have no idea what it is

#

or, I have some idea but no details

frosty blaze
#

first one, "JCL" is "Job Control Language", it is a language used on mainframes to tell the system how to run programs/utilities/subsystems. In this case, my JCL is:

  1. Deleting the previous sorted files (have to do this or else the system will try to create new files that already exist, which it will fail on. alternatively, could've run the sort steps once then comment out that code, since they do the same thing every time. I just wanted to have something similar to real-world production-ready JCL)
  2. Running the sort utility to extract the left and right lists and sort them, and then put them into their own files
  3. Running my cobol program with those 2 files from the previous step as input files
#

And most people know what COBOL is, though it is a common misconception nowadays that new COBOL isn't written anymore - it most certianly is, and it's part of my job

lilac cedar
#

why

#

this looks atrocious

frosty blaze
#

because mainframes are very much still around

#

but yes, the language itself is pretty awful and definately requires a unique way of thinking

#

I'm hoping there will be a challenge on a later day that requires large data processing because that's what mainframes excel at and I also have an extremely large pool of CPU cycles at my disposal

fading hamlet
frosty blaze
#

Oh true

lilac cedar
#

"has a solution" does not imply an obvious solution

#

ok did discord change the font for italics again, it looks so trippy

fading hamlet
#

The problems with obvious suboptimal solutions that a regular PC can't brute force are unfortunately also the kind of problems where every computer on the planet put together probably couldn't brute force in a reasonable timeframe 😛

#

or they're very serial in nature

lilac cedar
#

back in my competition days the problems were designed to have several solutions of different complexity