Skip to content

Commit 4336bed

Browse files
authored
Add A002110 Primorial Numbers sequence (TheAlgorithms#294)
1 parent 874422c commit 4336bed

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System.Linq;
2+
using System.Numerics;
3+
using Algorithms.Sequences;
4+
using FluentAssertions;
5+
using NUnit.Framework;
6+
7+
namespace Algorithms.Tests.Sequences
8+
{
9+
public class PrimorialNumbersSequenceTests
10+
{
11+
[Test]
12+
public void First10ElementsCorrect()
13+
{
14+
var sequence = new PrimorialNumbersSequence().Sequence.Take(10);
15+
sequence.SequenceEqual(new BigInteger[]
16+
{ 1, 2, 6, 30, 210, 2310, 30030, 510510, 9699690, 223092870 })
17+
.Should().BeTrue();
18+
}
19+
}
20+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System.Collections.Generic;
2+
using System.Numerics;
3+
4+
namespace Algorithms.Sequences
5+
{
6+
/// <summary>
7+
/// <para>
8+
/// Sequence of primorial numbers: product of first n primes.
9+
/// </para>
10+
/// <para>
11+
/// Wikipedia: https://wikipedia.org/wiki/Primorial.
12+
/// </para>
13+
/// <para>
14+
/// OEIS: https://oeis.org/A002110.
15+
/// </para>
16+
/// </summary>
17+
public class PrimorialNumbersSequence : ISequence
18+
{
19+
/// <summary>
20+
/// Gets sequence of primorial numbers.
21+
/// </summary>
22+
public IEnumerable<BigInteger> Sequence
23+
{
24+
get
25+
{
26+
var primes = new PrimesSequence().Sequence;
27+
var n = new BigInteger(1);
28+
29+
foreach (var p in primes)
30+
{
31+
yield return n;
32+
n *= p;
33+
}
34+
}
35+
}
36+
}
37+
}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ This repository contains algorithms and data structures implemented in C# for ed
109109
* [A000720 PrimePi](./Algorithms/Sequences/PrimePiSequence.cs)
110110
* [A001462 Golomb's](./Algorithms/Sequences/GolombsSequence.cs)
111111
* [A001478 Negative Integers](./Algorithms/Sequences/NegativeIntegersSequence.cs)
112+
* [A002110 Primorial Numbers](./Algorithms/Sequences/PrimorialNumbersSequence.cs)
112113
* [A005132 Recaman's](./Algorithms/Sequences/RecamansSequence.cs)
113114
* [A006879 Number of Primes by Number of Digits](./Algorithms/Sequences/NumberOfPrimesByNumberOfDigitsSequence.cs)
114115
* [A006880 Number of Primes by Powers of 10](./Algorithms/Sequences/NumberOfPrimesByPowersOf10Sequence.cs)

0 commit comments

Comments
 (0)