Project Euler Problem #56 Solution

We effectively search a 100 × 100 grid and find the cell with the greatest digital sum. Using some functional magic, we can do this:

from itertools import *

pairs = product(range(1, 100), range(1, 100))
exponentials = imap(lambda pair: pair[0] ** pair[1], pairs)
strings = imap(lambda exponential: str(exponential), exponentials)
sums = imap(lambda string: sum(map(lambda digit: int(digit), string)), strings)

print max(sums)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s