Created
May 2, 2018 14:38
-
-
Save Neverik/6b326787b1c6a22cbcc2c7ececc1c287 to your computer and use it in GitHub Desktop.
Perfect phi calculator - from a quick burst of inspiration.
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
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