Skip to content

Instantly share code, notes, and snippets.

@Neverik
Created May 2, 2018 14:38
Show Gist options
  • Save Neverik/6b326787b1c6a22cbcc2c7ececc1c287 to your computer and use it in GitHub Desktop.
Save Neverik/6b326787b1c6a22cbcc2c7ececc1c287 to your computer and use it in GitHub Desktop.
Perfect phi calculator - from a quick burst of inspiration.
phi = 1
precision = 0.5
while True:
n1 = phi + precision
n2 = phi - precision
diff1 = abs((n1 - 1 / n1) - 1)
diff2 = abs((n2 - 1 / n2) - 1)
if diff1 < diff2:
precision = diff1
phi = n1
else:
precision = diff2
phi = n2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment