Skip to content

Instantly share code, notes, and snippets.

@beoliver
Last active August 29, 2015 14:22
Show Gist options
  • Save beoliver/102ec38d3435acf2fb27 to your computer and use it in GitHub Desktop.
Save beoliver/102ec38d3435acf2fb27 to your computer and use it in GitHub Desktop.
def memoize(f):
computed = {}
def memoized(*args):
xs = computed.get(args)
if xs :
return xs
else :
value = f(*args)
computed[args] = value
return value
return memoized
def fact(n):
print("computing", n)
if n == 0:
return 1
else:
return fact(n-1) * n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment