Skip to content

Instantly share code, notes, and snippets.

@z-------------
Created November 6, 2014 01:34
Show Gist options
  • Save z-------------/b32e54d26b3f742da0c0 to your computer and use it in GitHub Desktop.
Save z-------------/b32e54d26b3f742da0c0 to your computer and use it in GitHub Desktop.
Golden sequences in Python
#!/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