Skip to content

Instantly share code, notes, and snippets.

@kyodaisuu
Created December 10, 2019 15:28
Show Gist options
  • Save kyodaisuu/19d400c511753a3e610e4d3c5fa7c7ff to your computer and use it in GitHub Desktop.
Save kyodaisuu/19d400c511753a3e610e4d3c5fa7c7ff to your computer and use it in GitHub Desktop.
Graham's number
#!/usr/bin/python
# coding: utf-8
# Print Graham's number
#
# Just a code for showing definition.
# It causes runtime error of maximum recursion.
def G(n):
# G function of Graham's number
if n == 0:
return 4
return uparrow(3,3,G(n-1))
def uparrow(a,b,n):
# a↑^n b = a→b→n
if b == 0:
return 1
if n == 1:
return a**b
return uparrow(a, uparrow(a, b-1, n), n-1)
# Print Graham's number
print(G(64))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment