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)