Skip to content

Instantly share code, notes, and snippets.

@fmasanori
Last active June 2, 2020 21:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save fmasanori/7034743 to your computer and use it in GitHub Desktop.
Save fmasanori/7034743 to your computer and use it in GitHub Desktop.
42 metaprogramming
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