In this exercise you're going to write an iterator that iterates through the first n
elements of the Fibonacci sequence.
The Fibonacci sequence is a sequence of numbers, where every element of the sequence is calculated by adding the two numbers that come before it.
You can think of a sequence as a list of numbers in a certain order.
The first two numbers of the sequence are set to
The start of the sequence is $1,~1,~2,~3,~5,~8,~13,~21,~34,~55,89,\dots$
In maths notation:
For example, the third element would be
!!! note
Some sources define the first elements as
julia> Fib(10)
Fib(10)
julia> for a in Fib(10)
println(a)
end
1
1
2
3
5
8
13
21
34
55
You can ignore integer overflow in your implementation.
The tests will only test for n
small enough to not cause overflow problems.
julia> collect(Fib(10))
10-element Array{Any,1}:
1
1
2
3
5
8
13
21
34
55
4. Define the optional methods that are necessary for Julia to infer the type of the elements of the iterator
julia> collect(Fib(10))
10-element Array{Int64,1}:
1
1
2
3
5
8
13
21
34
55