Created
January 28, 2015 16:09
-
-
Save patrickbeeson/b2505a7de937ec9d963b to your computer and use it in GitHub Desktop.
Python Callables with Hysterersis
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
>>> class Factorial(Callable): | |
... def __init__(self): | |
... self.previous = {} | |
... def __call__(self, n): | |
... if n not in self.previous: | |
... self.previous[n] = self.compute(n) | |
... return self.previous[n] | |
... def compute(self, n): | |
... if n == 0 : return 1 | |
... return n*self.__call__(n-1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment