The Best of Creative Computing Volume 1 (published 1976)

 `Page 170 << PREVIOUS >> NEXT Jump to page: Go to contents Go to thumbnails`

Palindromes: For Those Who Like to End at the Beginning (BASIC program to test if a number is a palindrome)

```[image]
Palindromes (con't)
Tom Karzes, an eighth grader at Curtis Jr. High
School, Sudbury, MA wrote a program to take any
number and test whether it is a palindrome; if it is
not the program goes on to form the palindrome.

The programs fails with greater than a 7-digit
number. Can you write one that doesn't?

LISTNH
10 REM *** TOM kARZES, CURTIS JR HS SUDBERY, MA
11 PRINT \INPUT "GIVE ME A NUMBER";A\PRINT\B=0
20 B=B+1\A=A/10\ IF INT <A>>0 THEN 20
30 FOR C=B TO 1 STEP -1\A=A+10\B<C> = INT<A-10+INT<A/10>>\NEXT C
40 D=0\FOR C=1 TO INT<B/2>\ IF B<C><>B<B+1-C> THEN D=1\NEXT C
50 FOR C=B TO 1 STEP -1\ PRINT CHR\$<B<C>+48); \NEXT C
60 IF D=1 THEN 69
65 PRINT " IS A PALINDROME "\GOTO 10
69 PRINT " IS NOT A PALINDROME, "\GOTO 10
70 IF B/2>INT<B/2> THEN B<INT<B/2>+1> =2*B<INT<B/2>+1
72 FOR C=1 TO INT<B/2>\B<C>=B<C>=B<C>+B<B+1-C>\NEXT C
75 FOR C=1 TO INT <B/2>\B<B+1-C>=B<C\NEXT C
80 B<B+1>=0\FOR C=1 TO B\B<C+1>=B<C+1> + INT<B<C>/10>
90 B<C>=B<C>-10+INT<B<C>/10>\NEXT C
100 IF B<B+1>>0 THEn B=B+1
110 GOTO 40
120 END

RUNNH
GIVE ME A NUMGER? 19
19 IS NOT A PALINDROME,
110 IS NOT A PALINDROME,
121 IS A PALINDROME.

GIVE ME A NUMBER? 38
38 IS NOT A PALINDROME,
121 IS A PALINDROME.

GIVE ME A NUMBER? 79
79 IS NOT A PALINDROME,
176 IS NOT A PALINDROME,
847 IS NOT A PALINDROME,
1595 IS NOT A PALINDROME,
7546 IS NOT A PALINDROME,
14003 IS NOT A PALINDROME,
440044 IS A PALINDROME.

GIVE ME A NUMBER? 96
96 IS NOT A PALINDROME,
165 IS NOT A PALINDROME,
726 IS NOT A PALINDROME,
1352 IS NOT A PALINDROME,
4884 IS A PALINDROME.

[image]

HOW MANY BLOCKS DO YOU SEE? 6 OR 7?>

[image]
1675 - NON-PALINDROMIC?

Mike Lean in England the the number 1675 and reversed it 4850 times with the
help of a computer, of course. Thise 4850 reversals produced a 2000-digit number
which was still not palindromic. Darryl Francis of Games and Puzzles thinks it's
reasonable to assume that 1675 will never become palindromic however many times
it is reversed. Do you agree?

Spell them backward and they stay the same

Read it from right to left and it will fe the same as when you read the usual
left to right. What will be? A palindrome, that is what.

Here is a sample: WON'T PEWS FILL IS SWEPT NOW?

YOu can have a lot of fun creating your own palindromes. But before you get

TOO HOT TO HOOT.

A POTATO PA?

NO, IT IS OPEN ON ONE POSITION.

STRAP ON NO PARTS.

WAS IT A BAR OR A BAT I SAW?

And this one is more difficult to read aloud:

OH HO HAH HAAHA AHAH HAH OH HO!

You can do the same with numbers, Example: 25952.

When your friends ask you what a palindrowm is, tell then, "A palindrome looks
and spells exactly the same from left to right or right to left, backward or
forward, or forward or backward." In a popular dictionary this example is
printed: ABLE WAS I ERE I SAW ELBA.

A few commercial names are palidromes. In California a city is name Yreka; a
merchant calls his bakery Yreka Bakery.

And don't overlook single words: HUH. PEP. EYE. ADA. POP. WOW.

At first, making your own will be a slow process, but as you work with them it
will become easier. Many adults know at least a few such words, so ask for their
help. Friends at schools may have one or two. And how about your teachers?
Write all of them down before you forget some. Try to make a long list, so you
can show it to friends,Page 170        << PREVIOUS        >> NEXT        Jump to page:                Go to contents        Go to thumbnails

<!--