forked from TheAlgorithms/C-Sharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FactorialSequence.cs
37 lines (36 loc) · 929 Bytes
/
FactorialSequence.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
using System.Collections.Generic;
using System.Numerics;
namespace Algorithms.Sequences
{
/// <summary>
/// <para>
/// Sequence of factorial numbers.
/// </para>
/// <para>
/// Wikipedia: https://en.wikipedia.org/wiki/Factorial.
/// </para>
/// <para>
/// OEIS: https://oeis.org/A000142.
/// </para>
/// </summary>
public class FactorialSequence : ISequence
{
/// <summary>
/// Gets sequence of factorial numbers.
/// </summary>
public IEnumerable<BigInteger> Sequence
{
get
{
var n = 0;
var factorial = new BigInteger(1);
while (true)
{
yield return factorial;
n++;
factorial *= n;
}
}
}
}
}