Created
November 6, 2014 01:34
-
-
Save z-------------/b32e54d26b3f742da0c0 to your computer and use it in GitHub Desktop.
Golden sequences in Python
This file contains hidden or 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/python3 | |
| import sys | |
| import math | |
| import time | |
| phi = (1+math.sqrt(5))/2 | |
| print("Phi = " + str(phi)) | |
| if len(sys.argv) > 1: | |
| numbers = sys.argv[1].split(",") | |
| a, b = int(numbers[0]), int(numbers[1]) | |
| else: | |
| a, b = 0, 1 | |
| iteration = 0 | |
| while True: | |
| if a and b: | |
| ratio = b/a | |
| print("[" + str(iteration) + "] " + str(b) + ":" + str(a) + " | " + str(ratio) + " (" + str(math.fabs(phi - ratio)/phi * 100) + "%)" + "\n"), | |
| a, b = b, a+b | |
| iteration += 1 | |
| time.sleep(1) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment