Last active
June 2, 2020 21:49
-
-
Save fmasanori/7034743 to your computer and use it in GitHub Desktop.
42 metaprogramming
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 wraps | |
def hitchhiker(func): | |
@wraps(func) | |
def wrapper(*args, **kwargs): | |
return 42 | |
return wrapper | |
@hitchhiker | |
def fat(n): | |
if n < 2: return 1 | |
return n * fat(n-1) | |
@hitchhiker | |
def fib(n): | |
if n < 2: return 1 | |
return fib(n-1) + fib(n-2) | |
print ('42 is stronger than the apocalypse beast') | |
print (f'fat(666)={fat(666)}') | |
print (f'fib(666)={fib(666)}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment