Skip to content

Instantly share code, notes, and snippets.

@timothy-shields
Created October 20, 2016 17:01
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 timothy-shields/aa3e295df8827fda2f4363edeeecb0a4 to your computer and use it in GitHub Desktop.
Save timothy-shields/aa3e295df8827fda2f4363edeeecb0a4 to your computer and use it in GitHub Desktop.
from functools import lru_cache
def make_E(U):
@lru_cache(maxsize=None)
def memoized_E(z, t):
if z < t:
return (1.0 / 6.0) * (U(0) + sum(E(z + i, t) for i in [1, 2, 3, 4, 5]))
else:
return U(z)
def E(z, t):
return memoized_E(z, max(z, t))
return E
E = make_E(lambda x: x)
print(E(z=0, t=15))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment