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
Changes from 1 commit
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
34 changes: 23 additions & 11 deletions project_euler/problem_56/sol1.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
def maximum_digital_sum(a,b):
'''
Considering natural numbers of the form, a**b, where a, b < 100,
what is the maximum digital sum?
:param a:
:param b:
:return:
'''
import typing
Copy link
Member

@cclauss cclauss Aug 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not need to be imported if it is not being used.

https://travis-ci.org/TheAlgorithms/Python/builds/571406392#L568



def maximum_digital_sum(a,b) -> 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
print(maximum_digital_sum(10,10), "is 45")
print(maximum_digital_sum(100,100), "is 972")
print(maximum_digital_sum(100,200), "is 1872")
if __name__ == "__main__":
import doctest
doctest.testmod()