Skip to content

Solution for Problem Euler 56 #1131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
26 changes: 26 additions & 0 deletions project_euler/problem_56/sol1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@


def maximum_digital_sum(a: int, b: int) -> int:
"""
Considering natural numbers of the form, a**b, where a, b < 100,
what is the maximum digital sum?
:param a:
:param b:
:return:
>>> maximum_digital_sum(10,10)
45

>>> maximum_digital_sum(100,100)
972

>>> maximum_digital_sum(100,200)
1872
"""

# RETURN the MAXIMUM from the list of SUMs of the list of INT converted from STR of BASE raised to the POWER
return max([sum([int(x) for x in str(base**power)]) for base in range(a) for power in range(b)])

#Tests
if __name__ == "__main__":
import doctest
doctest.testmod()