A challenge from the Mensa Puzzle Calendar

Marco Mariani marco at sferacarta.com
Thu Oct 3 16:00:03 EDT 2002


On Thu, Oct 03, 2002 at 12:25:28PM -0700, Chris Myers wrote:

> (NOTE: I realize this is not really a Python thingy, but more of an
> algorithm design thingy, but nonetheless, fun.)

Why use an algorithm when you've got a gigahertz CPU and a list
comprehension?


import string
print [ (x,y,x*y) for x in range(1000) for y in range(100)
        if map( lambda a: string.count(str(x)+str(y)+str(x*y),a),
        map(str,range(10)))==[1]*10 ]


(yes, this goes directly into the python hall of shame together with
my operator module)





More information about the Python-list mailing list