Skip to content

Commit 8952756

Browse files
Update sol1.py
1 parent 2e62f93 commit 8952756

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

project_euler/problem_164/sol1.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111

1212

1313
def solve(
14-
digit: int, prev: int, prev2: int, sum_max: int, first: bool, cache: dict[str, int]
14+
digit: int, prev1: int, prev2: int, sum_max: int, first: bool, cache: dict[str, int]
1515
) -> int:
1616
"""
17-
Solve for remaining 'digit' digits, with previous 'prev' number, and
17+
Solve for remaining 'digit' digits, with previous 'prev1' number, and
1818
previous-previous 'prev2' number, total sum of 'sum_max'.
1919
Pass around 'cache' to store/reuse intermediate results.
2020
@@ -26,13 +26,13 @@ def solve(
2626
if digit == 0:
2727
return 1
2828
comb = 0
29-
cache_str = f"{digit},{prev},{prev2}"
29+
cache_str = f"{digit},{prev1},{prev2}"
3030
if cache_str in cache:
3131
return cache[cache_str]
32-
for v in range(sum_max - prev - prev2 + 1):
32+
for v in range(sum_max - prev1 - prev2 + 1):
3333
if first and v == 0:
3434
continue
35-
comb += solve(digit - 1, v, prev, sum_max, False, cache)
35+
comb += solve(digit - 1, v, prev1, sum_max, False, cache)
3636
cache[cache_str] = comb
3737
return comb
3838

@@ -47,7 +47,7 @@ def solution(n_digits: int = 20) -> int:
4747
21838806
4848
"""
4949
cache: dict[str, int] = {}
50-
return solve(digit=n_digits, prev=0, prev2=0, sum_max=9, first=True, cache=cache)
50+
return solve(digit=n_digits, prev1=0, prev2=0, sum_max=9, first=True, cache=cache)
5151

5252

5353
if __name__ == "__main__":

0 commit comments

Comments
 (0)