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

Function get_digit_power

dynamic_programming/narcissistic_number.py:65–69  ·  view source on GitHub ↗

Get digit^power using memoization (DP optimization).

(digit: int, power: int)

Source from the content-addressed store, hash-verified

63 power_cache: dict[tuple[int, int], int] = {}
64
65 def get_digit_power(digit: int, power: int) -> int:
66 """Get digit^power using memoization (DP optimization)."""
67 if (power, digit) not in power_cache:
68 power_cache[(power, digit)] = digit**power
69 return power_cache[(power, digit)]
70
71 # Check each number up to the limit
72 for number in range(limit):

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected