nfirvine.comwiki

4

Filed in: Euler.4 · Modified on : Wed, 06 Feb 08

Description

No smart tricks here. Just brute force goodness.

However, I did learn something useful. Apparently list[::-1] reverses a list (not in place). list[:] would be a copy, and the extra :-1 emoticony thing is extended slice notation for "step by -1" (i.e., backwards). Radical.

import math
print max([x*y
        for x in xrange(100,999)
        for y in xrange(100,999)
        if str(x*y)[:int(math.floor(len(str(x*y))/2.))] == str(x*y)[int(math.ceil(len(str(x*y))/2.)):][::-1]
])

Powered by PmWiki