Arithmetrix

Type
Education
Category
Number tricks / mind-reading demo
Author
Jerry White
Published in
Antic, October 1983 (Vol. 2, No. 7)
Year
1983
Language
Atari BASIC
Requirements
16K RAM, Atari BASIC
A purple GRAPHICS 0 screen with centred text: ARITHMETRIX by Jerry White, an explanation of the five number tricks, and PRESS START TO CONTINUE

About the program

Jerry White, Antic's technical consultant, wrote this "simple Atari BASIC program" to fool your friends into thinking the computer can read their minds. He credited the idea to Sid Hyman. You think of a number and do some sums on paper, typing in only the results the program asks for. Each time it announces your original number, or tells you your final result before you've typed it. As White said, "there isn't any magic at all. It's all BASIC logic." The REMs date this version to 25 May 1983.

What you need

Atari BASIC and a pencil.

Typing it in

Plain ASCII apart from inverse-video REM headings, which you can type normally or leave out. All the on-screen text is in the DATA from line 980. Because a comma separates DATA items, White used @ wherever a comma should appear on screen, and line 200 swaps it back. Keep the DATA lines in order, because the program READs them in sequence.

How to use it

RUN it, press START, then follow the instructions, pressing RETURN after each entry. White's sample run uses the number 5. The five tricks, and why they work:

  1. Multiply (n+1) by (n−1). The answer is n²−1, so line 320 takes SQR(RESULT+1).
  2. Multiply by 3, say odd or even, then add 1 if it was odd, halve, multiply by 3, subtract 6 and divide by 9, ignoring any remainder. Line 430 or 440 rebuilds the number as 2*RESULT+1 or 2*RESULT+2.
  3. Give the remainders after dividing by 3, 4 and 5 (number under 60). Line 550 uses the classic Chinese remainder formula: (40A + 45B + 36C) mod 60.
  4. Take a three-digit number whose first and last digits differ by more than 1. Reverse it, subtract the smaller from the larger, reverse that and add. The answer is always 1089, and the program says so before you type it.
  5. Multiply by 6, add 36, halve, then subtract 3 × your number. Always 18.

How it works

  • The display subroutine at line 170 centres each line (LM=INT(19-LEN(LINE$)/2)) and prints it character by character, with a tiny "ding" from the sound loop in line 230. When the screen is full, it pauses using the countdown timer at location 540 and clears.
  • TRAP 830 and the variable RLINE give friendly error handling. If you type something that isn't a number, you get "I DON'T UNDERSTAND THAT" and a bong, and the program jumps back to the right INPUT with GOTO RLINE.
  • Each trick picks its next lines of text by RESTORE-ing to a DATA line number.

Listing

100 REM ARITHMETRIX by Jerry White
105 REM {inv}ANTIC MAGAZINE{/inv}
110 REM Version date 5/25/83
120 REM
130 DIM LINE$(40),R$(4),C$(1):GOSUB 790:GOTO 270
140 REM
150 REM {inv}DISPLAY SUBROUTINE{/inv}
160 REM
170 POKE 752,1:LM=INT(19-LEN(LINE$)/2):Y=Y+2:IF Y<24 THEN 190
180 JIFFY=120:GOSUB 760:? CHR$(125):Y=2
190 FOR DISPLAY=1 TO LEN(LINE$):X=LM+DISPLAY
200 C$=LINE$(DISPLAY,DISPLAY):IF C$="@" THEN C$=","
210 POSITION X,Y:? C$;:NEXT DISPLAY:RETURN
220 FOR LINE=1 TO LINES:READ LINE$:GOSUB 170
230 FOR DING=4 TO 0 STEP -1:SOUND 0,LINE,2,DING:NEXT DING:NEXT LINE:RETURN
240 REM
250 REM {inv}MAIN PROGRAM{/inv}
260 REM
270 Y=0:LINES=10:GOSUB 220:? :GOSUB 860
280 REM
290 REM {inv}FIRST ALGORITHM{/inv}
300 REM
310 LINES=2:GOSUB 220:GOSUB 820
320 N=SQR(RESULT+1):GOSUB 920
330 REM
340 REM {inv}SECOND ALGORITHM{/inv}
350 REM
360 LINES=2:GOSUB 220
370 POKE 752,0:? :POKE 764,255:INPUT R$
380 IF R$(1,1)<>"O" AND R$(1,1)<>"E" THEN RLINE=410:GOTO 830
390 IF R$="O" THEN RESTORE 1120
400 IF R$="E" THEN RESTORE 1130
410 LINES=1:GOSUB 220
420 RESTORE 1140:LINES=3:GOSUB 220:GOSUB 820
430 IF R$(1,1)="O" THEN N=2*RESULT+1
440 IF R$(1,1)="E" THEN N=2*RESULT+2
450 GOSUB 920
460 REM
470 REM {inv}THIRD ALGORITHM{/inv}
480 REM
490 LINES=4:GOSUB 220:POKE 752,0:?
500 TRAP 830:RLINE=510:POKE 764,255:INPUT A
510 LINES=2:GOSUB 220:POKE 752,0:?
520 TRAP 830:RLINE=530:POKE 764,255:INPUT B
530 LINES=2:GOSUB 220:POKE 752,0:?
540 TRAP 830:RLINE=550:POKE 764,255:INPUT C
550 S=40*A+45*B+36*C:Q=S/60:Z=(Q-INT(Q))*60:N=INT(Z+0.05)
560 TRAP 40000:GOSUB 920
570 REM
580 REM {inv}FOURTH ALGORITHM{/inv}
590 REM
600 LINES=11:GOSUB 220:FINAL=1
610 INPUT R$:N=1089:? CHR$(125):? :GOSUB 920
620 REM
630 REM {inv}FIFTH ALGORITHM{/inv}
640 REM
650 LINES=6:GOSUB 220
660 POKE 764,255:INPUT R$:N=18:? :DONE=1:GOSUB 920
670 REM
680 REM {inv}END OF PROGRAM{/inv}
690 REM
700 GRAPHICS 0:POKE 764,255:? :? "BASIC":? "IS";:END
710 REM
720 REM {inv}SUBROUTINES{/inv}
730 REM
740 FOR DING=8 TO 0 STEP -2:SOUND 0,0,2,DING:NEXT DING:RETURN
750 FOR BONG=4 TO 0 STEP -0.1:SOUND 0,102,12,BONG:NEXT BONG:RETURN
760 POKE 540,JIFFY
770 IF PEEK(540) THEN 770
780 RETURN
790 GRAPHICS 0:C=INT(RND(0)*16)
800 SETCOLOR 2,C,2:SETCOLOR 4,C,2:SETCOLOR 1,C,12
810 RETURN
820 ? :LINE$="ENTER THE RESULT THEN PRESS RETURN":GOSUB 170:GOTO 850
830 ? :LINE$="I DON'T UNDERSTAND THAT":GOSUB 170:GOSUB 750:IF RLINE THEN GOTO RLINE
840 GOTO 820
850 POKE 752,0:? :TRAP 830:POKE 764,255:INPUT RESULT:RETURN
860 POKE 752,1:? :? "      PRESS START TO CONTINUE";:GOSUB 740
870 IF PEEK(53279)<>6 THEN 870
880 IF PEEK(53279)=6 THEN 880
890 IF DONE THEN RETURN
900 GOSUB 790:GOSUB 910:RETURN
910 Y=-1:LINE$="Select a positive whole number.":GOSUB 170:GOSUB 740:RETURN
920 POKE 752,1:IF FINAL THEN 940
930 ? :? "     YOUR ORIGINAL NUMBER IS ";N:GOSUB 860:RETURN
940 ? :? "      YOUR FINAL RESULT IS ";N:GOSUB 860:RETURN
950 REM
960 REM {inv}DISPLAY DATA{/inv}
970 REM
980 DATA ARITHMETRIX by Jerry White
990 DATA This program will demonstrate five
1000 DATA simple number tricks.  In each case
1010 DATA you will choose a positive whole
1020 DATA number and write it down.
1030 DATA The program will ask you to make
1040 DATA calculations and enter results.
1050 DATA ARITHMETRIX will then give you the
1060 DATA value of your original number or
1070 DATA the results of your calculations.
1080 DATA Multiply (your number+1)
1090 DATA by (your number-1).
1100 DATA Multiply your number by 3 then
1110 DATA tell me if the result is Odd or Even.
1120 DATA Add 1 to the result then divide by 2.
1130 DATA Divide the new result by 2@
1140 DATA multiply by 3@ subtract 6@
1150 DATA then divide by 9.
1160 DATA Disregard any remainder.
1170 DATA This time your number must be
1180 DATA less than 60.
1190 DATA Divide your original number by 3 then
1200 DATA enter the remainder.
1210 DATA Divide your original number by 4 then
1220 DATA enter the remainder.
1230 DATA Divide your original number by 5 then
1240 DATA enter the remainder.
1250 DATA This time you must use a three digit
1260 DATA number.  The difference between the
1270 DATA first and last digit must be greater
1280 DATA than 1.  Reverse the order of your
1290 DATA number and label it RESULT1.
1300 DATA Find the difference between your
1310 DATA original number and RESULT1@ and
1320 DATA label it RESULT2.  Reverse the digits
1330 DATA of RESULT2@ and label it RESULT3.
1340 DATA Add RESULT2 to RESULT3
1350 DATA then press the RETURN key.
1360 DATA Multiply your number by 6 then add 36.
1370 DATA Divide the result by 2@ and label it
1380 DATA RESULT1.  Multiply your original
1390 DATA number by 3@ and label it RESULT2.
1400 DATA Subtract RESULT2 from RESULT1
1410 DATA then press the RETURN key

Download

The original program from the Antic disk, to LOAD or ENTER instead of typing it: ARITHMTX.BAS.

Credits