FANDOM


Problem 4 Edit

A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 99.

Find the largest palindrome made from the product of two 3-digit numbers.

Notes: Edit

At first I wasn't sure how to do this since there's no integer<->string conversion in ball, or any string substring routines. However I came up with this hack:

Code Edit

new number sum 0
new number ta 901
new number tb 901
new number best 0
new number tm
new number ac
new number dig1
new number dig2
new number dig3
new number dig4
new number dig5
new number dig6
hereis tal
set #tb 901
hereis tbl
set #tm #ta * #tb
set #ac 0
set #dig1 #tm / 100000
set #ac #dig1 * 100000
set #tm #tm - #ac
set #dig2 #tm / 10000
set #ac #dig2 * 10000
set #tm #tm - #ac
set #dig3 #tm / 1000
set #ac #dig3 * 1000
set #tm #tm - #ac
set #dig4 #tm / 100
set #ac #dig4 * 100
set #tm #tm - #ac
set #dig5 #tm / 10
set #ac #dig5 * 10
set #tm #tm - #ac
set #dig6 #tm / 1
if #dig1 ! #dig6 break
if #dig2 ! #dig5 break
if #dig3 ! #dig4 break
set #ac 1
hereis break
if #ac = 1 L1
hereis L0
set #tb #tb + 1
if #tb < 999 tbl
set #ta #ta + 1
if #ta < 999 tal
goto ex
hereis L1
set #tm #ta * #tb
if #tm > #best L2
hereis L3
goto L0
hereis L2
set #best #tm
goto L3
hereis ex
write #best