Skip to content

Instantly share code, notes, and snippets.

@alex-polosky
Last active September 9, 2018 03:14
Show Gist options
  • Save alex-polosky/dcc90b77e514eee49810e77570591e9d to your computer and use it in GitHub Desktop.
Save alex-polosky/dcc90b77e514eee49810e77570591e9d to your computer and use it in GitHub Desktop.
from math import sqrt
def arb(n, A, B):
return ((sqrt(5) + 1) / 2) ** n * ((3 * sqrt(5) - 5) * A + (5 - sqrt(5)) * B) / 10
def gen(l, A, B):
return [(n, int(round(arb(n, A, B)))) for n in range(l)]
def pprint(l, A, B):
for each in gen(l, A, B):
print("{0}: {1}".format(*each))
# Example:
# pprint(20, 1, 1):
# 0: 0
# 1: 1
# 2: 1
# 3: 2
# 4: 3
# 5: 5
# 6: 8
# 7: 13
# 8: 21
# 9: 34
# 10: 55
# 11: 89
# 12: 144
# 13: 233
# 14: 377
# 15: 610
# 16: 987
# 17: 1597
# 18: 2584
# 19: 4181
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment