forked from OmkarPathak/pygorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerator.py
More file actions
37 lines (30 loc) · 898 Bytes
/
generator.py
File metadata and controls
37 lines (30 loc) · 898 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"""
Fibonacci implementation through generator.
"""
import inspect
def get_sequence(n):
"""
Return Fibonacci sequence from zero to specified number as list.
"""
def fib():
"""
Return Fibonacci value by specified number as integer.
Golden ratio — https://en.wikipedia.org/wiki/Golden_ratio
Fibonacci's relation to the golden ratio — https://en.wikipedia.org/wiki/Fibonacci_number#Closed-form_expression
"""
a, b = 0, 1
while True:
yield a
a, b = b, a + b
def sequence(_n):
"""
Return sequence of Fibonacci values as list.
"""
f = fib()
return [f.__next__() for _ in range(_n + 1)]
return sequence(n)
def get_code():
"""
Return source code of Fibonacci sequence logic's implementation.
"""
return inspect.getsource(get_sequence)