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

Function solution

project_euler/problem_188/sol1.py:45–64  ·  view source on GitHub ↗

Returns the last 8 digits of the hyperexponentiation of base by height, i.e. the number base↑↑height: >>> solution(base=3, height=2) 27 >>> solution(base=3, height=3) 97484987 >>> solution(base=123, height=456, digits=4) 2547

(base: int = 1777, height: int = 1855, digits: int = 8)

Source from the content-addressed store, hash-verified

43
44
45def solution(base: int = 1777, height: int = 1855, digits: int = 8) -> int:
46 """
47 Returns the last 8 digits of the hyperexponentiation of base by
48 height, i.e. the number base↑↑height:
49
50 >>> solution(base=3, height=2)
51 27
52 >>> solution(base=3, height=3)
53 97484987
54 >>> solution(base=123, height=456, digits=4)
55 2547
56 """
57
58 # calculate base↑↑height by right-assiciative repeated modular
59 # exponentiation
60 result = base
61 for _ in range(1, height):
62 result = _modexpt(base, result, 10**digits)
63
64 return result
65
66
67if __name__ == "__main__":

Callers 1

sol1.pyFile · 0.70

Calls 1

_modexptFunction · 0.85

Tested by

no test coverage detected