- Notifications
You must be signed in to change notification settings - Fork 1.6k
/
Copy pathFibonacciSequence.cs
39 lines (37 loc) · 898 Bytes
/
FibonacciSequence.cs
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
38
39
usingSystem.Collections.Generic;
usingSystem.Numerics;
namespaceAlgorithms.Sequences;
/// <summary>
/// <para>
/// Fibonacci sequence.
/// </para>
/// <para>
/// Wikipedia: https://wikipedia.org/wiki/Fibonacci_number.
/// </para>
/// <para>
/// OEIS: https://oeis.org/A000045.
/// </para>
/// </summary>
publicclassFibonacciSequence:ISequence
{
/// <summary>
/// Gets Fibonacci sequence.
/// </summary>
publicIEnumerable<BigInteger>Sequence
{
get
{
yieldreturn0;
yieldreturn1;
BigIntegerprevious=0;
BigIntegercurrent=1;
while(true)
{
varnext=previous+current;
previous=current;
current=next;
yieldreturnnext;
}
}
}
}