Contribution for Puzzlet #026
From: Denis Borris [borrisd@ca.inter.net]
Program quite simple; half-english:
(6digit = a, 5digit = b and 4digit = c)
loop k from 663 increment of 1
get a by constructing palindrome using k [ex: 663366]
calculate m [mileage so far]
if b+m and c+m not both palindromes then k=k+1 and carry on
print a,b,c,m
end here if you only want one !
Notes:
-using 3digit k reduces looping in ratio 9:1
-it is easier not to worry about a, b+m and c+m
exceeding odometer size; simply "get" the last
6/5/4 digits of each.
Thanks, Denis. This is faster than my original algorithm, and I've adopted it in my solution. My approach to odomoter overflows is modular arithmetic. Dave.
| Site design/maintenance: Dave Ellis | E-mail
me! |
Last Updated: February 22nd, 2004. |