Created
October 20, 2016 17:01
-
-
Save timothy-shields/aa3e295df8827fda2f4363edeeecb0a4 to your computer and use it in GitHub Desktop.
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
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