Skip to content

Instantly share code, notes, and snippets.

@SuperShinyEyes
Last active March 7, 2019 07:53
Show Gist options
  • Save SuperShinyEyes/db4daad1f1bd5d671a8a89664ecc7f3b to your computer and use it in GitHub Desktop.
Save SuperShinyEyes/db4daad1f1bd5d671a8a89664ecc7f3b to your computer and use it in GitHub Desktop.
import numpy as np
from scipy import constants
def fibonacci(n):
"""Calculate fibonacci system in signal processing way; weighted sum of fundamental modes.
The complexity: O(1).
"""
p = constants.golden
return int(np.around(
(p / (np.sqrt(5) ) * np.power(p, n)) + \
(1 / (np.sqrt(5) * p) * np.power(-p, -n))
))
for i in range(22):
print(fibonacci(i))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment