Skip to content

Commit

Permalink
Merge de6076d into 996de27
Browse files Browse the repository at this point in the history
  • Loading branch information
hrhwilliams committed Oct 23, 2018
2 parents 996de27 + de6076d commit 4ea3c7f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ If you want to uninstall algorithms, it is as simple as:
- [euler_totient](algorithms/maths/euler_totient.py)
- [extended_gcd](algorithms/maths/extended_gcd.py)
- [factorial](algorithms/maths/factorial.py)
- [fibonacci](algorithms/maths/fibonacci.py)
- [gcd/lcm](algorithms/maths/gcd.py)
- [generate_strobogrammtic](algorithms/maths/generate_strobogrammtic.py)
- [is_strobogrammatic](algorithms/maths/is_strobogrammatic.py)
Expand Down
19 changes: 19 additions & 0 deletions algorithms/maths/fibonacci.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
""" Fibonacci sequence
Generates a list consisting of fibonacci numbers from F(0)
to F(n) for the input n
Arguments:
n -- The nth fibonacci number to generate to.
simulation -- whether or not the script should return info
about an estimation of phi
"""
def fibonacci(n, simulation=False):
f_nums = [1,1]
for x in range(1,n):
f_nums.append(f_nums[x-1] + f_nums[x])
if (simulation):
phi = (1 + 5**0.5)/2
print(f_nums)
print("F({}) - F({}) = {}".format(n, n-1, f_nums[-1]/f_nums[-2]))
print("The true value of phi is {}".format(phi))
return f_nums

0 comments on commit 4ea3c7f

Please sign in to comment.