Python Implementation of Problem 56

View source code here on GitHub!

Includes

Problem Solution

Project Euler Problem 56

Problem:

A googol (10100) is a massive number: one followed by one-hundred zeros; 100100 is almost unimaginably large: one followed by two-hundred zeros. Despite their size, the sum of the digits in each number is only 1.

Considering natural numbers of the form, ab, where a, b < 100, what is the maximum digital sum?

python.src.p0056.main() int
 1"""
 2Project Euler Problem 56
 3
 4Problem:
 5
 6A googol (10100) is a massive number: one followed by one-hundred zeros; 100100 is almost unimaginably large: one
 7followed by two-hundred zeros. Despite their size, the sum of the digits in each number is only 1.
 8
 9Considering natural numbers of the form, ab, where a, b < 100, what is the maximum digital sum?
10"""
11from .lib.iters import digits
12
13
14def main() -> int:
15    answer = 0
16    for x in range(2, 100):
17        for y in range(1, 100):
18            answer = max((answer, sum(digits(x**y))))
19    return answer

Tags: large-numbers, digit-sum, python-iterator