[Tutor] A fun puzzle

Kent Johnson kent37 at tds.net
Thu Aug 23 04:34:17 CEST 2007


R. Alan Monroe wrote:
> I wrote a lame, but working script to solve this in a few minutes. A
> fun puzzle.

FWIW here is my fastest solution:

from itertools import chain
def compute():
     str_=str; int_=int; slice_=slice(None, None, -1)
     for x in chain(xrange(1, 1000001, 10), xrange(2, 1000001, 10), 
xrange(3, 1000001, 10), xrange(4, 1000001, 10), xrange(5, 1000001, 10), 
xrange(6, 1000001, 10), xrange(7, 1000001, 10), xrange(8, 1000001, 10), 
xrange(9, 1000001, 10)):
         rev = int_(str_(x)[slice_])
         if rev>=x: continue
         if not x % rev:
              print x,
compute()

Kent


More information about the Tutor mailing list