Follow-up on Palindromes Remember in the Jan.-Feb. issue on page 12 we asked if readers could improve on Tom Karzes' programs to turn any number into a palindrome by successive reversals and adding. Here's an example: 76 67 --- 143 341 --- 484 a palindrome In the Jan.-Feb. issue we said Tom Karzes' palindrome program "fails with greater than a 7-digit number." What we really should have said is that it will not accept input numbers of over seven digits. In retrospect, this is not much of a limitation at all since palindromic seed numbers are generally much less than 7 digits. His program, in fact, spews out a number as long as a Teletype line. Sorry, Tom! In any event, Gregory Yob of Menlo Park, CA put some additional sophistication into a palindromic reversal program. Here's the program, a couple of sample runs and then a portion of the run using 196 as a starter (remember - that's the one that doesn't seem to ever become palindromic). Gregory interrupted that run after 101 additions. He then wrote a souped up version that doesn't print out the calculations but rather just the final palindrome and number of steps to reach it. If a palindrome isn't formed by 254 digits the program quits and prints the last number. Here's a listing of the second program and a couple of sample runs including the run of 196 as a starter. Want to carry on? Why not modify the program to try all the numbers between 100 and 200 in sequence? Or extend it, if your BASIC compiler permits, to handle a longer number? *** 0070 DIM A$[254],B$[254],C$[254] 0080 PRINT "STARTING #"; 0090 INPUT A$ 0100 S=0 0110 REM- PRINT LAST SUM 0120 PRINT TAB(10);AS 0130 REM: MAKE REVERSED # 0140 FOR J=LEN(A$) TO 1 STEP -1 0150 K=LEN(A$)-J 1 0160 B$[K:K]=A$[J:J] 0170 NEXT J 0180 REM: PRINT REVERSED # & STEP COUNT 0190 S=S 1 0200 PRINT S;TAB(11);B$ 0210 REM- DO THE ADDITION 0220 C$=A$ B$ 0230 REM: RESET AND DO AGAIN 0240 A$=C$ 0250 B$=" " 0260 PRINT 0270 GOTO 120 0280 END *** [image]LISTING *** STARTING #?176 176 1 671 847 2 748 1595 3 5951 7546 4 6457 14003 5 30041 44044 6 44044 *** STARTING #?776 776 1 677 1453 2 3541 4994 *** STARTING #?2344 2344 1 4432 6776 2 6776 *** [image]SAMPLE RUNS[image] *** [image]AND HERE'S THE BIG ONE (196) [image]WE DIDN'T HAVE SPACE FOR ALL THE INTERMEDIATE PRINT-OUT (YOU RUN IT!). GREGORY ABORTED THE RUN AFTER 101 ADDITIONS. *** STARTING #?196 196 1 691 887 2 788 1675 3 5761 7436 4 6347 7074449215608204801780891870975115165118444806 99 6084448115618115790781980871084028065129444707 13158897331226320592562872742059146230247889513 100 31598874203264195024727826529502362213379885131 44757771534490515617290699271561508443627774644 101 44647772634480516517299609271651509443517775744 *** 0010 REM: FIND A PALINDROMIC NUMBER BY REVERSALS AND ADDITIONS 0020 REM: BY FREGORY YOB (415) 326-4039 0030 REM: PO BOX 310, MENLO PARK, CALIFORNIA 94025 0040 REM: --- INSPIRED BY ARTICLE IN CREATIVE COMPUTING 0050 REM: --- RUN ON BASIC TIMESHARING SYSTEM 3000 0060 REM: --- WHICH HAS LIMITED STRING ARITHMETIC 0070 DIM A$[254],B$[254],C$[254] 0080 PRINT "STARTING #"; 0090 INPUT A$ 0100 S=0 0110 REM- PRINT LAST SUM 0120 REM: REMOVED TO ELIMINATE PRINTOUT 0130 REM: MAKE REVERSED # 0140 B$=" " 0150 FOR J=LEN(A$) TO 1 STEP -1 0160 REM: RESULT STRING BEGINS WITH A BLANK, SO: 0170 K=LEN(A$)-J 2 0180 IF A$(J:J)="" THEN 200 0190 B$[K:K]=A$[J:J] 0200 NEXT J 0210 REM: PRINT REVERSED # & STEP COUNT 0220 S=S 1 0230 REM: REMOVED & REPLACED BY A TEST 0240 IF A$=B$ THEN 340 0250 IF LEN(A$)=254 THEN 320 0260 REM- DO THE ADDITION 0270 C$=A$ B$ 0280 REM: RESET AND DO AGAIN 0290 A$=C$ 0300 B$=" " 0310 GOTO 140 0320 PRINT "IS NOT "; 0330 GOTO 350 0340 PRINT 0350 PRINT "PALINDROMIC AT STEP "S-1 0360 PRINT " THE NUMBER IS:" 0370 PRINT A$(1:70) 0380 IF LEN(A$)<71 THEN 450 0390 PRINT A$(71:140) 0400 IF LEN(A$)<141 THEN 450 0410 PRINT A$(141:210) 0420 IF LEN(A$)<211 THEN 450 0430 PRINT A$(211:254) 0440 GOTO 450 0450 END *** HERE'S THE SOUPED UP VERSION OF THE PROGRAM *** [image]AND HERE'S THE RUN USING 196 AS A STARTER. *** [image]USER INTERRUPT TO FIND OUT WHERE WE ARE *** [image]PROGRAM HALTED AT STEP # 584 WHEN NUMBER FORMED 254 DIGITS, THE MAXIMUM STRING SIZE OF SYSTEM. *** STARTING #?196 STOPPED AT 200 XI?PRINT S;LEN(A$) 425 188 XI?PRINT A$ 60239554322389886717750708169963186816112861056083174321936723138176880 622203953811987008220121132600680205448313126923572231215729124371309660 15732161867046896290705761858987432246582305 XI? GOTO 200 IS NOT PALINDROMIC AT STEP 584 THE NUMBER IS: 179783220484416006808962247253580610457420253934734211705030836407528 4812966783124693965464737561164092999951577064625923388740047774319526 4717751599982013522557373744703865302976682185924704639030507112338428 46201385302697635373226089760062438403328896 *** A Non-Palindrome ? Ever since the first article on palindromes appeared in Creative Computing in January 1975, l have received letters from people discussing the notorious 196(or 1675). 1675 is merely two reversals and additions of 196 (196 691 = 887. 887 788 = 1675). Three magazines seem to be keeping track of this problem. Darryl Francis of Games & Puzzles printed letters from R. Hamilton who reversed 196 100 times with no palindrome formed, Jonathan Kessell (4147 reversals), and Mike Lean (4850). Students of Fred Gruenberger, editor of Popular Computing reversed 196 well over 5000 times. Gregory Yob's program is printed here with which he performed 584 reversals. Tony Skaltsiotis and Andrew Glassner of Highland Park High School, N.J. took it out to 10,000 reversals. The ultimate so far was done by Lynn Yarbrough who dedicated 3 hours of a CDC 6600 to the problem and performed 79,098 reversals. Still no palindrome. (Details of his run are in Creative Computing, Vol. 2, No. 1, page 34. *** 171