Skip to content

Instantly share code, notes, and snippets.

Created January 6, 2013 14:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/4467595 to your computer and use it in GitHub Desktop.
Save anonymous/4467595 to your computer and use it in GitHub Desktop.
Crash pythonista
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