Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def prob5():
- def helper1(n, m, a):
- list = [ ]
- list.append(a)# saves the last number = 9
- for n in range(1, n): # checks every number for n up to 9
- num = [ 0 ] * m
- for i in range(m):
- if i == 0:
- num[i] = list[n-1][1]
- elif i == m - 1:
- num[i] = list[n-1][i-1]
- else:
- num[i] = list[n-1][i-1] + list[n-1][i+1]
- list.append(num)
- return sum(map(sum, list)) # i keep the numbers mapped rather than using of using dictionary which i helps
- # i use that to memmoize
- def helper2(n, start, end):
- m = end - start + 1
- if start == 0:
- a = [ 0 ] + [ 1 ] * (m - 1)
- else:
- a = [ 1 ] * m
- return helper1(n, end - start + 1, a) # plus one so i can use range and still get the correct numbers
- N = 40
- return helper2(N, 0, 9) - helper2(N, 0, 8) - helper2(N, 1, 9) + helper2(N, 1, 8) # returns the count of numbers
- """
- here i got a bit confused for it always returned 1931330459886 so i battled a bit more and got it after some
- some googeling :) that you need to find where the number has 0 and 9 than subtrackt the numbers which have
- 0 but not 9 , neither 0 ore 9 and than add the numbers that include 9 but not 0
Add Comment
Please, Sign In to add comment