--- title: "Enigma" id: 72040 type: "computer_media" slug: "enigma" url: "http://localhost/computer_media/enigma/" markdown_url: "http://localhost/computer_media/enigma.md" published_at: "2026-10-20T14:07:38+00:00" modified_at: "2026-10-20T14:19:11+00:00" author: "David Anderson" featured_image: url: "http://localhost/wp-content/uploads/2026/10/5_ENIGMA.png" excerpt: "A number-reversal trick: subtract a number's reverse, then add the result to its own reverse, and see the total the arithmetic always produces." category: - name: "Archived Media" slug: "archived-media" taxonomy: "category" url: "http://localhost/category/archived-media/" post_tag: - name: "Downloadable" slug: "downloadable" taxonomy: "post_tag" url: "http://localhost/tag/downloadable/" - name: "TS 1000" slug: "ts1000" taxonomy: "post_tag" url: "http://localhost/tag/ts1000/" model: - name: "Timex/Sinclair 1000" slug: "ts-1000" taxonomy: "model" url: "http://localhost/model/ts-1000/" indiv: - name: "Gene G. Buza" slug: "gene-g-buza" taxonomy: "indiv" url: "http://localhost/indiv/gene-g-buza/" genre: - name: "Demo" slug: "demo" taxonomy: "genre" url: "http://localhost/type/demo/" media_contents: - id: 72046 title: "Synchro-Sette May 1984" type: "computer_media" url: "http://localhost/computer_media/synchro-sette-may-1984/" media_type: "Program" programmers: - name: "Gene G. Buza" slug: "gene-g-buza" taxonomy: "indiv" url: "http://localhost/indiv/gene-g-buza/" mediadate: "1984" images: - url: "http://localhost/wp-content/uploads/2026/10/5_ENIGMA.png" media_type_tags: "Demo" --- # Enigma Demonstrates a number trick. Enter a number and the program reverses its digits, prints the difference between the number and its reverse, then reverses that difference and adds the two together. With most three-digit numbers whose first and last digits differ, the final total is always 1089. *** ## Program Analysis The program is about twenty lines. The number is taken as a string so that it can be reversed character by character (lines 50–70), and `VAL` turns both forms back into numbers. The positive difference is worked out with two `IF` tests, turned into a string with `STR$`, reversed the same way and added to itself. `PAUSE 40000` waits for a key before the program restarts with `RUN`. ### Potential Issues - If the number reads the same in both directions, neither `IF` at lines 110–120 sets `C`, so line 130 stops with an error on the first run and prints the previous value later. - A two-digit difference such as 99 is reversed as “99” and not “990”, because the program does not pad it to three digits. Such numbers give 198 in place of 1089. ## Source Code ``` 10 PRINT "ENTER A NUMBER?" 20 INPUT A$ 30 LET A=VAL A$ 40 LET B$="" 50 FOR N=LEN A$ TO 1 STEP -1 60 LET B$=B$+A$(N) 70 NEXT N 80 PRINT ,,,,"DIFFERENCE BETWEEN ";A$ 90 PRINT "AND ";B$;" IS:" 100 LET B=VAL B$ 110 IF (A-B)>0 THEN LET C=A-B 120 IF (B-A)>0 THEN LET C=B-A 130 PRINT C 140 LET C$=STR$ C 150 LET D$="" 160 FOR N=LEN C$ TO 1 STEP -1 170 LET D$=D$+C$(N) 180 NEXT N 190 LET D=VAL D$ 200 PRINT ,,C;" + ";D;" = ";C+D 210 PAUSE 40000 220 CLS 230 RUN 9998 SAVE "ENIGM[A]" 9999 RUN ```