Skip to content

Instantly share code, notes, and snippets.

@rrbutani
Last active April 19, 2025 21:34
Show Gist options
  • Save rrbutani/e7ad8641ee86a16d2ad0780ae4c6f0f1 to your computer and use it in GitHub Desktop.
Save rrbutani/e7ad8641ee86a16d2ad0780ae4c6f0f1 to your computer and use it in GitHub Desktop.
0: [.] succ(a, ): add `1` to `a`
1: [+] add(a, b): ret = a; ret = succ(ret) `b` times
2: [*] mul(a, b): ret = 0; ret = add(ret, a) `b` times
3: [^] exp(a, b): ret = 1; ret = mul(ret, a) `b` times
4: [!] tetration(a, b): ret = a; ret = exp(ret, a) `b - 1` times (special case b = 0 -> 1)
5: [@] pentation(a, b): ret = a; ret = tetration(ret, a) `b - 1` times (special case b = 0 -> 1)
6: [#] hexation(a, b): ret = a; ret = pentation(ret, a) `b - 1` times (special case b = 0 -> 1)
3 . -> 4
3 + 4 -> 7 { ((((3 . ) . ) . ) . ) }
3 * 4 -> 12 { ((((0 + 3) + 3) + 3) + 3) }
3 ^ 4 -> 81 { ((((1 * 3) * 3) * 3) * 3) }
3 ! 4 -> 7,625,597,484,987 { (((( 3) ^ 3) ^ 3) ^ 3) }
3 @ 5 -> { (((( 3) ! 3) ! 3) ! 3) }
3 # 6 -> { (((( 3) @ 3) @ 3) @ 3) }
from functools import reduce as fold; from itertools import repeat
hyperop = lambda rank: (
(lambda a, _: a + 1) if not rank else
lambda a, b: fold(
hyperop(rank - 1),
repeat(a, b - (b and rank >= 3)),
{1:a, 2:0}.get(rank, a if b and rank >= 3 else 1),
)
)
# incorrect, unfortunately:
# lambda a, b: fold(hyperop(rank - 1), repeat(a, b), {1:a, 2:0}.get(rank, 1))
succ = hyperop(0)
add = hyperop(1)
mul = hyperop(2)
exp = hyperop(3)
tetr = hyperop(4)
pent = hyperop(5)
hexa = hyperop(6)
[print(f"[{n}] {hyperop(n)(3, 4)=}") for n in range(0, 6)]
from functools import reduce as f;from itertools import repeat as n
h=lambda r:(lambda a,b:f(h(r-1),n(a,b-(z:=(b and r>2))),{1:a,2:0}.get(r,a if z else 1))) if r else lambda a,_:a+1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment