Skip to content

Commit

Permalink
Problem 164 - solved
Browse files Browse the repository at this point in the history
  • Loading branch information
dionyziz committed Aug 22, 2013
1 parent de7923e commit 246e689
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions problem-164/164.py
@@ -0,0 +1,22 @@
N = 20 # number of digits in number
B = 10 # base
K = 9 # maximum sum of three consecutive digits

DP = [None, {(0, 0): 0}]

for d in range(1, B):
DP[1][(0, d)] = 1

for i in range(2, N + 1):
DP.append({})
for a in range(0, B):
for b in range(0, B):
DP[i][(a, b)] = 0
for d in range(0, B):
if a + b + d <= 9:
try:
DP[i][(a, b)] += DP[i - 1][(d, a)]
except:
pass

print(sum(DP[N].values()))

0 comments on commit 246e689

Please sign in to comment.