MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / solution

Function solution

project_euler/problem_056/sol1.py:13–34  ·  view source on GitHub ↗

Considering natural numbers of the form, a**b, where a, b < 100, what is the maximum digital sum? :param a: :param b: :return: >>> solution(10,10) 45 >>> solution(100,100) 972 >>> solution(100,200) 1872

(a: int = 100, b: int = 100)

Source from the content-addressed store, hash-verified

11
12
13def solution(a: int = 100, b: int = 100) -> int:
14 """
15 Considering natural numbers of the form, a**b, where a, b < 100,
16 what is the maximum digital sum?
17 :param a:
18 :param b:
19 :return:
20 >>> solution(10,10)
21 45
22
23 >>> solution(100,100)
24 972
25
26 >>> solution(100,200)
27 1872
28 """
29
30 # RETURN the MAXIMUM from the list of SUMs of the list of INT converted from STR of
31 # BASE raised to the POWER
32 return max(
33 sum(int(x) for x in str(base**power)) for base in range(a) for power in range(b)
34 )
35
36
37# Tests

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected