File tree 3 files changed +54
-7
lines changed
3 files changed +54
-7
lines changed Original file line number Diff line number Diff line change 25
25
"""
26
26
27
27
28
- def fibonacci (n ):
28
+ def fibonacci (n : int ) -> int :
29
+ """
30
+ Computes the Fibonacci number for input n by iterating through n numbers
31
+ and creating an array of ints using the Fibonacci formula.
32
+ Returns the nth element of the array.
33
+
34
+ >>> fibonacci(2)
35
+ 1
36
+ >>> fibonacci(3)
37
+ 2
38
+ >>> fibonacci(5)
39
+ 5
40
+ >>> fibonacci(10)
41
+ 55
42
+ >>> fibonacci(12)
43
+ 144
44
+
45
+ """
29
46
if n == 1 or type (n ) is not int :
30
47
return 0
31
48
elif n == 2 :
@@ -38,7 +55,21 @@ def fibonacci(n):
38
55
return sequence [n ]
39
56
40
57
41
- def fibonacci_digits_index (n ):
58
+ def fibonacci_digits_index (n : int ) -> int :
59
+ """
60
+ Computes incrementing Fibonacci numbers starting from 3 until the length
61
+ of the resulting Fibonacci result is the input value n. Returns the term
62
+ of the Fibonacci sequence where this occurs.
63
+
64
+ >>> fibonacci_digits_index(1000)
65
+ 4782
66
+ >>> fibonacci_digits_index(100)
67
+ 476
68
+ >>> fibonacci_digits_index(50)
69
+ 237
70
+ >>> fibonacci_digits_index(3)
71
+ 12
72
+ """
42
73
digits = 0
43
74
index = 2
44
75
@@ -49,8 +80,9 @@ def fibonacci_digits_index(n):
49
80
return index
50
81
51
82
52
- def solution (n ):
53
- """Returns the index of the first term in the Fibonacci sequence to contain
83
+ def solution (n : int = 1000 ) -> int :
84
+ """
85
+ Returns the index of the first term in the Fibonacci sequence to contain
54
86
n digits.
55
87
56
88
>>> solution(1000)
Original file line number Diff line number Diff line change 25
25
"""
26
26
27
27
28
- def fibonacci_generator ():
28
+ def fibonacci_generator () -> int :
29
+ """
30
+ A generator that produces numbers in the Fibonacci sequence
31
+
32
+ >>> generator = fibonacci_generator()
33
+ >>> next(generator)
34
+ 1
35
+ >>> next(generator)
36
+ 2
37
+ >>> next(generator)
38
+ 3
39
+ >>> next(generator)
40
+ 5
41
+ >>> next(generator)
42
+ 8
43
+ """
29
44
a , b = 0 , 1
30
45
while True :
31
46
a , b = b , a + b
32
47
yield b
33
48
34
49
35
- def solution (n ) :
50
+ def solution (n : int = 1000 ) -> int :
36
51
"""Returns the index of the first term in the Fibonacci sequence to contain
37
52
n digits.
38
53
Original file line number Diff line number Diff line change 25
25
"""
26
26
27
27
28
- def solution (n ) :
28
+ def solution (n : int = 1000 ) -> int :
29
29
"""Returns the index of the first term in the Fibonacci sequence to contain
30
30
n digits.
31
31
You can’t perform that action at this time.
0 commit comments