On 2026-10-11 10:54 AM,
docdwarf@panix.com wrote:
In article <hq6dnR6bKpYFnFb3nZ2dnZfqn_qdnZ2d@giganews.com>,
Arnold Trembley <arnold.trembley@att.net> wrote:
Found this in a thread in the GnuCOBOL forums. It's a link to a website
for creating a COBOL program using AI prompts.
MAIN-PARA. Ain't seen one of those in a while.
DD
I asked it to create a program that performs a credit card Mod 10 check
digit validation using the Luhn algorithm, which is described in a
Wikipedia article:
https://en.wikipedia.org/wiki/Luhn_algorithm
The check digit algorithm is intended to detect digit transposition or substitution when a credit card number is manually typed.
In this case it generated a "MAIN-LOGIC" paragraph instead of
"MAIN-PARA", but the generated COBOL looked pretty reasonable. I
compiled it with GnuCOBOL 3.2 and it appeared to execute correctly, and
I also tested it with different "card numbers" generated with difference
check digit values.
IDENTIFICATION DIVISION.
PROGRAM-ID. LUHN-VALIDATOR.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-INPUT.
05 WS-CARD-NUMBER PIC X(16) VALUE "49927398716".
01 WS-VARIABLES.
05 WS-I PIC 9(2) COMP.
05 WS-DIGIT PIC 9(2) COMP.
05 WS-SUM PIC 9(4) COMP VALUE 0.
05 WS-DOUBLED PIC 9(2) COMP.
05 WS-REMAINDER PIC 9(2) COMP.
05 WS-MOD-RESULT PIC 9(4) COMP.
01 WS-TABLE.
05 WS-TABLE-DIGITS PIC X OCCURS 16 TIMES.
01 WS-OUTPUT-MSG.
05 WS-RESULT-MSG PIC X(30).
PROCEDURE DIVISION.
MAIN-LOGIC.
PERFORM INITIALIZATION
PERFORM VALIDATE-LUHN
PERFORM DISPLAY-RESULT
STOP RUN.
INITIALIZATION.
MOVE WS-CARD-NUMBER TO WS-TABLE.
MOVE 0 TO WS-SUM.
VALIDATE-LUHN.
PERFORM VARYING WS-I FROM 16 BY -1 UNTIL WS-I < 1
MOVE WS-TABLE-DIGITS(WS-I) TO WS-DIGIT
IF FUNCTION MOD(WS-I, 2) = 1
COMPUTE WS-DOUBLED = WS-DIGIT * 2
IF WS-DOUBLED > 9
COMPUTE WS-DOUBLED = WS-DOUBLED - 9
END-IF
ADD WS-DOUBLED TO WS-SUM
ELSE
ADD WS-DIGIT TO WS-SUM
END-IF
END-PERFORM.
DISPLAY-RESULT.
COMPUTE WS-MOD-RESULT = FUNCTION MOD(WS-SUM, 10)
IF WS-MOD-RESULT = 0
DISPLAY "CREDIT CARD NUMBER IS VALID."
ELSE
DISPLAY "CREDIT CARD NUMBER IS INVALID."
END-IF.
Of course, this means the pointy-haired bosses will want all the new
programs written by AI bots, so they can pay us less.
Cheers,
--
https://www.arnoldtrembley.com/
--
This email has been checked for viruses by Avast antivirus software. www.avast.com
--- MBSE BBS v1.1.7.2 (Linux-x86_64)
* Origin: Air Applewood, The Linux Gateway to the UK & Eire (2:250/1@fidonet)