Skip to content

Instantly share code, notes, and snippets.

@Diapolo10
Last active January 19, 2020 13:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Diapolo10/f629200277e705e6afd837b304a120a7 to your computer and use it in GitHub Desktop.
Save Diapolo10/f629200277e705e6afd837b304a120a7 to your computer and use it in GitHub Desktop.
A general solution for the four fours problem
# log(log(sqrt(4), 4), (sqrt(4)/4)) == 1
import math
def repeat(func, n):
x = 4
for _ in range(n):
x = func(x)
return x
def four_fours(n):
inner = repeat(math.sqrt, n)
return round(math.log(math.log(inner, 4), (math.sqrt(4)/4)))
if __name__ == '__main__':
print("The four fours problem, first 100 solutions:")
subscript_digits = '₀₁₂₃₄₅₆₇₈₉'
print("Format: number, equation, calculated number")
for num in range(100):
inner = f"{'√' * num}4"
print(f"{num} = log₄(log√₄/₄({inner})) = {four_fours(num)}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment