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

Function solution

project_euler/problem_119/sol1.py:29–47  ·  view source on GitHub ↗

Returns the value of 30th digit power sum. >>> solution(2) 512 >>> solution(5) 5832 >>> solution(10) 614656

(n: int = 30)

Source from the content-addressed store, hash-verified

27
28
29def solution(n: int = 30) -> int:
30 """
31 Returns the value of 30th digit power sum.
32 >>> solution(2)
33 512
34 >>> solution(5)
35 5832
36 >>> solution(10)
37 614656
38 """
39 digit_to_powers = []
40 for digit in range(2, 100):
41 for power in range(2, 100):
42 number = int(math.pow(digit, power))
43 if digit == digit_sum(number):
44 digit_to_powers.append(number)
45
46 digit_to_powers.sort()
47 return digit_to_powers[n - 1]
48
49
50if __name__ == "__main__":

Callers 1

sol1.pyFile · 0.70

Calls 3

digit_sumFunction · 0.85
sortMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected