Created
January 6, 2013 14:38
-
-
Save anonymous/4467595 to your computer and use it in GitHub Desktop.
Crash pythonista
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def numDigitsInc(n,dPrev=None): | |
if n==1: | |
return dict(zip(range(1,10),[1]*9)) | |
if dPrev==None: | |
dPrev=numDigitsInc(n-1) | |
#if a number ends in n, the next digit can be either n, n+1, etc | |
newD = {} | |
for a in range(1,10): | |
z = 0 | |
for b in range(1,a+1): | |
z+=dPrev[b] | |
newD[a]=z | |
return newD | |
def numDigitsDec(n,dPrev=None): | |
if n==1: | |
d = dict(zip(range(1,10),[1]*9)) | |
d[0]=0 | |
if dPrev==None: | |
dPrev=numDigitsDec(n-1) | |
#if a number ends in n, the next digit can be either n, n+1, etc | |
newD = {} | |
for a in range(0,10): | |
z = 0 | |
for b in range(a,10): | |
z+=dPrev[b] | |
newD[a]=z | |
return newD | |
print(numDigitsDec(10)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment