WeixiangYan/CodeTransOcean huggingface dataset:
Task: Colour bars_Display







Python: 


from livewires import *

horiz=640; vert=480
begin_graphics(width=horiz,height=vert,title="v_stripes",background=Colour.black)
NameColors=["black","red","green","dark_blue","purple","blue","yellow","white"]
stepik=horiz/len(NameColors)

for index,each in enumerate(NameColors):
	ExcStrng="set_colour(Colour."+each+")"
	exec ExcStrng
	box(index*stepik,0,(index+1)*stepik,vert,filled=1)

while keys_pressed() != ['x']: 
	pass

end_graphics()



COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. terminal-colour-bars.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  width           PIC 9(3).
       01  height          PIC 9(3).

       01  interval        PIC 9(3).

       01  colours-area.
           03  colour-values.
               05  FILLER  PIC 9 VALUE 0. 
               05  FILLER  PIC 9 VALUE 4. 
               05  FILLER  PIC 9 VALUE 2. 
               05  FILLER  PIC 9 VALUE 1. 
               05  FILLER  PIC 9 VALUE 5. 
               05  FILLER  PIC 9 VALUE 3. 
               05  FILLER  PIC 9 VALUE 6. 
               05  FILLER  PIC 9 VALUE 7. 

           03  colour-table REDEFINES colour-values.
               05  colours PIC 9 OCCURS 8 TIMES INDEXED BY colour-index.

       01  i               PIC 9(3).
       01  j               PIC 9(3).

       PROCEDURE DIVISION.
           ACCEPT width FROM COLUMNS
           ACCEPT height FROM LINES
           DIVIDE width BY 8 GIVING interval

           PERFORM VARYING i FROM 1 BY 1 UNTIL height < i
               PERFORM VARYING j FROM 1 BY 1 UNTIL width < j
                  COMPUTE colour-index = (j / interval) + 1
                  
                  IF 8 < colour-index
                      SET colour-index TO 8
                  END-IF

                  
                  
                  
                  DISPLAY SPACE AT LINE i COLUMN j
                      WITH BACKGROUND-COLOR colours (colour-index)
               END-PERFORM
           END-PERFORM

           ACCEPT i 

           GOBACK
           .
Task: Enforced immutability







Python: >>> s = "Hello"
>>> s[0] = "h"

Traceback (most recent call last):
  File "<pyshell
    s[0] = "h"
TypeError: 'str' object does not support item assignment



COBOL: ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SPECIAL-NAMES.
    SYMBOLIC CHARACTERS NUL IS 0, TAB IS 9.
Task: Strange numbers







Python: 



def isStrange(n):
    
    def test(a, b):
        return abs(a - b) in [2, 3, 5, 7]

    xs = digits(n)
    return all(map(test, xs, xs[1:]))




def main():
    

    xs = [
        n for n in range(100, 1 + 500)
        if isStrange(n)
    ]
    print('\nStrange numbers in range [100..500]\n')
    print('(Total: ' + str(len(xs)) + ')\n')
    print(
        '\n'.join(
            ' '.join(
                str(x) for x in row
            ) for row in chunksOf(10)(xs)
        )
    )





def chunksOf(n):
    
    def go(xs):
        return (
            xs[i:n + i] for i in range(0, len(xs), n)
        ) if 0 < n else None
    return go



def digits(n):
    
    return [int(c) for c in str(n)]



if __name__ == '__main__':
    main()



COBOL:         IDENTIFICATION DIVISION.
        PROGRAM-ID. STRANGE-NUMBERS.
        
        DATA DIVISION.
        WORKING-STORAGE SECTION.
        01 COMPUTATION.
           02 NUM           PIC 999.
           02 DIGITS        REDEFINES NUM PIC 9 OCCURS 3 TIMES.
           02 DIGIT-PRIME   PIC 9.
              88 PRIME      VALUES 2 3 5 7.
           02 CUR-DIGIT     PIC 9.
        01 OUTPUT-FORMAT.
           02 N-OUT         PIC ZZ9.
        PROCEDURE DIVISION.
        BEGIN.
            PERFORM STRANGE-TEST
                VARYING NUM FROM 100 BY 1
                UNTIL NUM IS GREATER THAN 500.
            STOP RUN.
        
        STRANGE-TEST SECTION.
        BEGIN.
            SET CUR-DIGIT TO 1.
        STEP.   
            IF DIGITS(CUR-DIGIT) IS LESS THAN DIGITS(CUR-DIGIT + 1)
                SUBTRACT DIGITS(CUR-DIGIT + 1) FROM DIGITS(CUR-DIGIT) 
                    GIVING DIGIT-PRIME
            ELSE
                SUBTRACT DIGITS(CUR-DIGIT) FROM DIGITS(CUR-DIGIT + 1)
                    GIVING DIGIT-PRIME.
            IF PRIME NEXT SENTENCE ELSE GO TO DONE.
            ADD 1 TO CUR-DIGIT.
            IF CUR-DIGIT IS LESS THAN 3 GO TO STEP.
            MOVE NUM TO N-OUT.
            DISPLAY N-OUT.
        DONE. EXIT.
Task: Hofstadter Q sequence







Python: def q(n):
    if n < 1 or type(n) != int: raise ValueError("n must be an int >= 1")
    try:
        return q.seq[n]
    except IndexError:
        ans = q(n - q(n - 1)) + q(n - q(n - 2))
        q.seq.append(ans)
        return ans
q.seq = [None, 1, 1]

if __name__ == '__main__':
    first10 = [q(i) for i in range(1,11)]
    assert first10 == [1, 1, 2, 3, 3, 4, 5, 5, 6, 6], "Q() value error(s)"
    print("Q(n) for n = [1..10] is:", ', '.join(str(i) for i in first10))
    assert q(1000) == 502, "Q(1000) value error"
    print("Q(1000) =", q(1000))



COBOL:         IDENTIFICATION DIVISION.
        PROGRAM-ID. Q-SEQ.
        
        DATA DIVISION.
        WORKING-STORAGE SECTION.
        01 SEQ.
           02 Q         PIC 9(3) OCCURS 1000 TIMES.
           02 Q-TMP1    PIC 9(3).
           02 Q-TMP2    PIC 9(3).
           02 N         PIC 9(4).
        01 DISPLAYING.
           02 ITEM      PIC Z(3).
           02 IX        PIC Z(4).
            
        PROCEDURE DIVISION.
        MAIN-PROGRAM.    
            PERFORM GENERATE-SEQUENCE.
            PERFORM SHOW-ITEM
                VARYING N FROM 1 BY 1 
                UNTIL N IS GREATER THAN 10.
            SET N TO 1000.
            PERFORM SHOW-ITEM.
            STOP RUN.
        
        GENERATE-SEQUENCE.
            SET Q(1) TO 1.
            SET Q(2) TO 1.            
            PERFORM GENERATE-ITEM 
                VARYING N FROM 3 BY 1
                UNTIL N IS GREATER THAN 1000.
        
        GENERATE-ITEM.
            COMPUTE Q-TMP1 = N - Q(N - 1).
            COMPUTE Q-TMP2 = N - Q(N - 2).
            COMPUTE Q(N) = Q(Q-TMP1) + Q(Q-TMP2).
                        
        SHOW-ITEM.
            MOVE N TO IX.
            MOVE Q(N) TO ITEM.
            DISPLAY 'Q(' IX ') = ' ITEM.
Task: Count occurrences of a substring







Python: >>> "the three truths".count("th")
3
>>> "ababababab".count("abab")
2



COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. testing.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  occurrences             PIC 99.

       PROCEDURE DIVISION.
           INSPECT "the three truths" TALLYING occurrences FOR ALL "th"
           DISPLAY occurrences

           MOVE 0 TO occurrences
           INSPECT "ababababab" TALLYING occurrences FOR ALL "abab"
           DISPLAY occurrences
           
           MOVE 0 TO occurrences
           INSPECT "abaabba*bbaba*bbab" TALLYING occurrences
               FOR ALL "a*b"
           DISPLAY occurrences

           GOBACK
           .
Task: Hickerson series of almost integers







Python: from decimal import Decimal
import math

def h(n):
    'Simple, reduced precision calculation'
    return math.factorial(n) / (2 * math.log(2) ** (n + 1))
    
def h2(n):
    'Extended precision Hickerson function'
    return Decimal(math.factorial(n)) / (2 * Decimal(2).ln() ** (n + 1))

for n in range(18):
    x = h2(n)
    norm = str(x.normalize())
    almostinteger = (' Nearly integer' 
                     if 'E' not in norm and ('.0' in norm or '.9' in norm) 
                     else ' NOT nearly integer!')
    print('n:%2i h:%s%s' % (n, norm, almostinteger))



COBOL:        >>SOURCE FREE
IDENTIFICATION DIVISION.
PROGRAM-ID. hickerson-series.

ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
REPOSITORY.
    FUNCTION ALL INTRINSIC
    .
DATA DIVISION.
WORKING-STORAGE SECTION.
01  n                                   PIC 99 COMP.

01  h                                   PIC Z(19)9.9(10).

01  First-Decimal-Digit-Pos             CONSTANT 22.

PROCEDURE DIVISION.
    PERFORM VARYING n FROM 0 BY 1 UNTIL n > 17
        COMPUTE h = FACTORIAL(n) / (2 * LOG(2) ** (n + 1))
        DISPLAY "h(" n ") = " h " which is " NO ADVANCING
        IF h (First-Decimal-Digit-Pos:1) = "0" OR "9"
            DISPLAY "an almost integer."
        ELSE
            DISPLAY "not an almost integer."
        END-IF
    END-PERFORM
    .
END PROGRAM hickerson-series.
Task: Sorting algorithms_Stooge sort







Python: >>> data = [1, 4, 5, 3, -6, 3, 7, 10, -2, -5, 7, 5, 9, -3, 7]
>>> def stoogesort(L, i=0, j=None):
	if j is None:
		j = len(L) - 1
	if L[j] < L[i]:
		L[i], L[j] = L[j], L[i]
	if j - i > 1:
		t = (j - i + 1) // 3
		stoogesort(L, i  , j-t)
		stoogesort(L, i+t, j  )
		stoogesort(L, i  , j-t)
	return L

>>> stoogesort(data)
[-6, -5, -3, -2, 1, 3, 3, 4, 5, 5, 7, 7, 7, 9, 10]



COBOL:        >>SOURCE FREE
IDENTIFICATION DIVISION.
PROGRAM-ID. stooge-sort-test.

DATA DIVISION.
WORKING-STORAGE SECTION.
01  Arr-Len                             CONSTANT 7.

01  arr-area                            VALUE "00004001000020000005000230000000000".
    03  arr-elt                         PIC 9(5) OCCURS Arr-Len TIMES
                                        INDEXED BY arr-idx.

PROCEDURE DIVISION.
    DISPLAY "Unsorted: " NO ADVANCING
    PERFORM VARYING arr-idx FROM 1 BY 1 UNTIL Arr-Len < arr-idx
        DISPLAY arr-elt (arr-idx) " " NO ADVANCING
    END-PERFORM
    DISPLAY SPACE

    CALL "stooge-sort" USING arr-area, OMITTED, OMITTED

    DISPLAY "Sorted:   " NO ADVANCING
    PERFORM VARYING arr-idx FROM 1 BY 1 UNTIL Arr-Len < arr-idx
        DISPLAY arr-elt (arr-idx) " " NO ADVANCING
    END-PERFORM
    DISPLAY SPACE
    .
END PROGRAM stooge-sort-test.
    

IDENTIFICATION DIVISION.
PROGRAM-ID. stooge-sort RECURSIVE.

DATA DIVISION.
LOCAL-STORAGE SECTION.
01  Arr-Len                             CONSTANT 7.

01  i                                   PIC 99 COMP.
01  j                                   PIC 99 COMP.

01  temp                                PIC 9(5).

01  t                                   PIC 99 COMP.

LINKAGE SECTION.
01  arr-area.
    03  arr-elt                         PIC 9(5) OCCURS Arr-Len TIMES.

01  i-val                               PIC 99 COMP.
01  j-val                               PIC 99 COMP.

PROCEDURE DIVISION USING arr-area, OPTIONAL i-val, OPTIONAL j-val.
    IF i-val IS OMITTED
        MOVE 1 TO i
    ELSE
        MOVE i-val TO i
    END-IF
    IF j-val IS OMITTED
        MOVE Arr-Len TO j
    ELSE
        MOVE j-val TO j
    END-IF
    
    IF arr-elt (j) < arr-elt (i)
        MOVE arr-elt (i) TO temp
        MOVE arr-elt (j) TO arr-elt (i)
        MOVE temp TO arr-elt (j)
    END-IF   
    
    IF j - i + 1 >= 3
        COMPUTE t = (j - i + 1) / 3
        SUBTRACT t FROM j
        CALL "stooge-sort" USING arr-area, CONTENT i, j
        ADD t TO i, j
        CALL "stooge-sort" USING arr-area, CONTENT i, j
        SUBTRACT t FROM i, j
        CALL "stooge-sort" USING arr-area, CONTENT i, j
    END-IF
    .
END PROGRAM stooge-sort.
Task: Digit fifth powers







Python: from time import time


st = time()
print(sum([n for n in range(2, 6*9**5) if sum(int(i)**5 for i in str(n)) == n]), "  ", (time() - st) * 1000, "ms")


st = time()
nums = list(range(10))
nu = list(range(((6 * 9**5) // 100000) + 1))
numbers = []
p5 = []
for i in nums: p5.append(i**5)
for i in nu:
    im = i * 100000
    ip = p5[i]
    for j in nums:
        jm = im + 10000 * j
        jp = ip + p5[j]
        for k in nums:
            km = jm + 1000 * k
            kp = jp + p5[k]
            for l in nums:
                lm = km + 100 * l
                lp = kp + p5[l]
                for m in nums:
                    mm = lm + 10 * m
                    mp = lp + p5[m]
                    for n in nums:
                        nm = mm + n
                        np = mp + p5[n]
                        if np == nm:
                            if nm > 1: numbers.append(nm)
print(sum(numbers), "  ", (time() - st) * 1000, "ms", end = "")



COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. DIGIT-FIFTH-POWER.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 VARIABLES.
          03 CANDIDATE          PIC 9(6).
          03 MAXIMUM            PIC 9(6).
          03 DIGITS             PIC 9 OCCURS 6 TIMES,
                                REDEFINES CANDIDATE.
          03 DIGIT              PIC 9.
          03 POWER-SUM          PIC 9(6).
          03 TOTAL              PIC 9(6).

       01 OUT-FORMAT.
          03 OUT-NUM            PIC Z(5)9.

       PROCEDURE DIVISION.
       BEGIN.
           MOVE ZERO TO TOTAL.
           COMPUTE MAXIMUM = 9 ** 5 * 6.
           PERFORM TEST-NUMBER
               VARYING CANDIDATE FROM 2 BY 1
               UNTIL CANDIDATE IS GREATER THAN MAXIMUM.
           DISPLAY '------ +'.
           DISPLAY TOTAL.
           STOP RUN.

       TEST-NUMBER.
           MOVE ZERO TO POWER-SUM.
           PERFORM ADD-DIGIT-POWER
               VARYING DIGIT FROM 1 BY 1
               UNTIL DIGIT IS GREATER THAN 6.
           IF POWER-SUM IS EQUAL TO CANDIDATE,
               MOVE CANDIDATE TO OUT-NUM,
               DISPLAY OUT-NUM,
               ADD CANDIDATE TO TOTAL.
       
       ADD-DIGIT-POWER.
           COMPUTE POWER-SUM = POWER-SUM + DIGITS(DIGIT) ** 5.
Task: McNuggets problem







Python: >>> from itertools import product
>>> nuggets = set(range(101))
>>> for s, n, t in product(range(100//6+1), range(100//9+1), range(100//20+1)):
	nuggets.discard(6*s + 9*n + 20*t)

	
>>> max(nuggets)
43
>>>



COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID.  MCNUGGETS.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 NUGGETS.
          03 NUGGET-FLAGS     PIC X OCCURS 100 TIMES.
             88 IS-NUGGET     VALUE 'X'.

       01 A                   PIC 999.
       01 B                   PIC 999.
       01 C                   PIC 999.

       PROCEDURE DIVISION.
       BEGIN.
           MOVE SPACES TO NUGGETS.
           PERFORM A-LOOP VARYING A FROM 0 BY 6
               UNTIL A IS GREATER THAN 100.
           MOVE 100 TO A.

       FIND-LARGEST.
           IF IS-NUGGET(A), SUBTRACT 1 FROM A, GO TO FIND-LARGEST.
           DISPLAY 'Largest non-McNugget number: ', A.
           STOP RUN.
 
       A-LOOP.
           PERFORM B-LOOP VARYING B FROM A BY 9
               UNTIL B IS GREATER THAN 100.

       B-LOOP.
           PERFORM C-LOOP VARYING C FROM B BY 20
               UNTIL C IS GREATER THAN 100.
 
       C-LOOP.
           IF C IS NOT EQUAL TO ZERO, MOVE 'X' TO NUGGET-FLAGS(C).
Task: Idiomatically determine all the lowercase and uppercase letters







Python: classes = (str.isupper, str.islower, str.isalnum, str.isalpha, str.isdecimal,
           str.isdigit, str.isidentifier, str.isnumeric, str.isprintable,
           str.isspace, str.istitle)

for stringclass in classes:
    chars = ''.join(chr(i) for i in range(0x10FFFF+1) if stringclass(chr(i)))
    print('\nString class %s has %i characters the first of which are:\n  %r'
          % (stringclass.__name__, len(chars), chars[:100]))



COBOL:        identification division.
       program-id. determine.

       environment division.
       configuration section.
       repository.
           function all intrinsic.

       data division.
       working-storage section.
       01 tx pic x.
       01 lower-8bit pic x(256).
       01 upper-8bit pic x(256).

      
      
      

       01 low-slide usage index.
       01 high-slide usage index.

       procedure division.
       determining.

      
       set low-slide to 0
       set high-slide to 0
       perform varying tally from 1 by 1 until tally > 256
           move char(tally) to tx
           if tx is alphabetic-lower then
               set low-slide up by 1
               move tx to lower-8bit(low-slide:1)
           end-if
           if tx is alphabetic-upper then
               set high-slide up by 1
               move tx to upper-8bit(high-slide:1)
           end-if
       end-perform
       if low-slide equal 0 then
           display "no lower case letters detected" upon syserr
       else
           display lower-8bit(1:low-slide)
       end-if
       if high-slide equal 0 then
           display "no upper case letters detected" upon syserr
       else
           display upper-8bit(1:high-slide)        
       end-if

      
      

      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      

       goback.
       end program determine.
Task: Find words which contains more than 3 e vowels







Python: with open('unixdict.txt', 'rt') as f:
    for line in f.readlines():
        if not any(c in 'aiou' for c in line) and sum(c=='e' for c in line)>3:
            print(line.strip())



COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. E-WORDS.
       
       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT DICT ASSIGN TO DISK
           ORGANIZATION LINE SEQUENTIAL.
           
       DATA DIVISION.
       FILE SECTION.
       FD DICT 
           LABEL RECORD STANDARD
           VALUE OF FILE-ID IS "unixdict.txt".
       01 WORD            PIC X(64).
       
       WORKING-STORAGE SECTION.
       01 E               PIC 99.
       01 OTHER           PIC 99.
       
       PROCEDURE DIVISION.
       BEGIN.
           OPEN INPUT DICT.
           
       READ-WORD.
           READ DICT, AT END CLOSE DICT, STOP RUN.
           PERFORM CHECK-WORD.
           GO TO READ-WORD.
           
       CHECK-WORD.
           MOVE ZERO TO E, OTHER.
           INSPECT WORD TALLYING OTHER FOR ALL 'a'.
           INSPECT WORD TALLYING E FOR ALL 'e'.
           INSPECT WORD TALLYING OTHER FOR ALL 'i'.
           INSPECT WORD TALLYING OTHER FOR ALL 'o'.
           INSPECT WORD TALLYING OTHER FOR ALL 'u'.
           IF E IS GREATER THAN 3 AND OTHER IS EQUAL TO ZERO,
               DISPLAY WORD.
Task: Numbers divisible by their individual digits, but not by the product of their digits.







Python: 

from functools import reduce
from operator import mul



def p(n):
    
    digits = [int(c) for c in str(n)]
    return not 0 in digits and (
        0 != (n % reduce(mul, digits, 1))
    ) and all(0 == n % d for d in digits)




def main():
    
    xs = [
        str(n) for n in range(1, 1000)
        if p(n)
    ]
    w = len(xs[-1])
    print(f'{len(xs)} matching numbers:\n')
    print('\n'.join(
        ' '.join(cell.rjust(w, ' ') for cell in row)
        for row in chunksOf(10)(xs)
    ))





def chunksOf(n):
    
    def go(xs):
        return (
            xs[i:n + i] for i in range(0, len(xs), n)
        ) if 0 < n else None
    return go



if __name__ == '__main__':
    main()



COBOL:         IDENTIFICATION DIVISION.
        PROGRAM-ID. DIV-BY-DGTS-BUT-NOT-PROD.
        
        DATA DIVISION.
        WORKING-STORAGE SECTION.
        01 CALCULATION.
           02 N             PIC 9(4).
           02 DGT-PROD      PIC 9(3).
           02 NSTART        PIC 9.
           02 D             PIC 9.
           02 N-INDEXING    REDEFINES N.
              03 DIGIT      PIC 9 OCCURS 4 TIMES.
           02 NDIV          PIC 9(4).
           02 OK            PIC 9.
        01 OUTPUT-FORMAT.
           02 DISP-N        PIC Z(4).
           
        PROCEDURE DIVISION.
        BEGIN.
            PERFORM CHECK VARYING N FROM 1 BY 1 
                    UNTIL N IS EQUAL TO 1000.
            STOP RUN.
            
        CHECK SECTION.
        BEGIN.
            SET NSTART TO 1.
            INSPECT N TALLYING NSTART FOR LEADING '0'.
            
            SET DGT-PROD TO 1.
            PERFORM MUL-DIGIT VARYING D FROM NSTART BY 1
                    UNTIL D IS GREATER THAN 4.
            IF DGT-PROD = 0 GO TO NOPE.
            SET OK TO 1.
            PERFORM CHECK-DIGIT VARYING D FROM NSTART BY 1
                    UNTIL D IS GREATER THAN 4.
            IF OK = 0 GO TO NOPE.
            DIVIDE N BY DGT-PROD GIVING NDIV.
            MULTIPLY DGT-PROD BY NDIV.
            IF NDIV IS EQUAL TO N GO TO NOPE.
            MOVE N TO DISP-N.
            DISPLAY DISP-N.
        MUL-DIGIT.
            IF D IS GREATER THAN 4 GO TO NOPE.
            MULTIPLY DIGIT(D) BY DGT-PROD.
        CHECK-DIGIT.
            IF D IS GREATER THAN 4 GO TO NOPE.
            DIVIDE N BY DIGIT(D) GIVING NDIV.
            MULTIPLY DIGIT(D) BY NDIV.
            IF NDIV IS NOT EQUAL TO N SET OK TO 0.
        NOPE. EXIT.
Task: Day of the week of Christmas and New Year







Python: import datetime

weekDays = ("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday")
thisXMas  = datetime.date(2021,12,25)
thisXMasDay = thisXMas.weekday()
thisXMasDayAsString = weekDays[thisXMasDay]
print("This year's Christmas is on a {}".format(thisXMasDayAsString))

nextNewYear = datetime.date(2022,1,1)
nextNewYearDay = nextNewYear.weekday()
nextNewYearDayAsString = weekDays[nextNewYearDay]
print("Next new year is on a {}".format(nextNewYearDayAsString))



COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. XMASNY.
       
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 WEEKDAYS.
          03 DAY-NAMES.
             05 FILLER   PIC X(9) VALUE "Saturday ".
             05 FILLER   PIC X(9) VALUE "Sunday   ".
             05 FILLER   PIC X(9) VALUE "Monday   ".
             05 FILLER   PIC X(9) VALUE "Tuesday  ".
             05 FILLER   PIC X(9) VALUE "Wednesday".
             05 FILLER   PIC X(9) VALUE "Thursday ".
             05 FILLER   PIC X(9) VALUE "Friday   ".
          03 DAYS        PIC X(9) OCCURS 7 TIMES,
                         REDEFINES DAY-NAMES.
       01 OUT-FMT.
          03 OUT-MONTH   PIC 99.
          03 FILLER      PIC X VALUE "/".
          03 OUT-DAY     PIC 99.
          03 FILLER      PIC X VALUE "/".
          03 OUT-YEAR    PIC 9(4).
          03 FILLER      PIC X(6) VALUE " is a ".
          03 OUT-DAYNAME PIC X(9).
       
       01 VARIABLES.
          03 CDATE.
             05 D-MONTH  PIC 99.
             05 D-DAY    PIC 99.
             05 D-YEAR   PIC 9999.
          03 ZELLER-DATA.
             05 M        PIC 99.
             05 Y        PIC 99.
             05 D        PIC 999.
             05 D7       PIC 999.
             05 J        PIC 99.
             05 K        PIC 99.
             05 DAY-NAME PIC X(9).
       
       PROCEDURE DIVISION.
       BEGIN.
           MOVE "25122021" TO CDATE.
           PERFORM SHOW-WEEKDAY.
           MOVE "01012022" TO CDATE.
           PERFORM SHOW-WEEKDAY.
           STOP RUN.
       
       SHOW-WEEKDAY.
           MOVE D-MONTH TO OUT-MONTH.
           MOVE D-DAY TO OUT-DAY.
           MOVE D-YEAR TO OUT-YEAR.
           PERFORM ZELLER.
           MOVE DAY-NAME TO OUT-DAYNAME.
           DISPLAY OUT-FMT.
       
       ZELLER.
           MOVE D-MONTH TO M.
           MOVE D-YEAR TO Y.
           IF M IS NOT GREATER THAN 2,
               ADD 12 TO M,
               SUBTRACT 1 FROM Y.
           DIVIDE Y BY 100 GIVING J.
           COMPUTE K = Y - J * 100.
           COMPUTE D = (M + 1) * 26.
           DIVIDE 10 INTO D.
           ADD K TO D.
           DIVIDE 4 INTO K.
           ADD K TO D.
           COMPUTE D = D + 5 * J.
           DIVIDE 4 INTO J.
           COMPUTE D = D + J + D-DAY.
           DIVIDE D BY 7 GIVING D7.
           MULTIPLY 7 BY D7.
           COMPUTE D = D - D7 + 1.
           MOVE DAYS(D) TO DAY-NAME.