Created
December 10, 2019 15:28
-
-
Save kyodaisuu/19d400c511753a3e610e4d3c5fa7c7ff to your computer and use it in GitHub Desktop.
Graham's number
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
#!/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