Skip to content

Instantly share code, notes, and snippets.

@yoniLavi
Created January 28, 2019 21:00
Show Gist options
  • Select an option

  • Save yoniLavi/6748cb1d562487e1dcbfa453ce951bf9 to your computer and use it in GitHub Desktop.

Select an option

Save yoniLavi/6748cb1d562487e1dcbfa453ce951bf9 to your computer and use it in GitHub Desktop.
"""Hyperoperations implementation (https://en.wikipedia.org/wiki/Hyperoperation)"""
from functools import reduce
zeration = lambda a, b: b+1
addition = lambda a, b: reduce(lambda x, _: zeration(0, x), [None]*b, a)
multiplication = lambda a, b: reduce(lambda x, _: addition(a, x), [None]*b, 0)
exponentiation = lambda a, b: reduce(lambda x, _: multiplication(a, x), [None]*b, 1)
tetration = lambda a, b: reduce(lambda x, _: exponentiation(a, x), [None]*b, 1)
pentation = lambda a, b: reduce(lambda x, _: tetration(a, x), [None]*b, 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment