Skip to content

Commit ed7f9b5

Browse files
authored
Add A001478 Negative Integers sequence (TheAlgorithms#283)
Co-authored-by: Oleksii Herasymenko <oherasy@softserveinc.com>
1 parent 4aab5b2 commit ed7f9b5

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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 NegativeIntegersSequenceTests
10+
{
11+
[Test]
12+
public void First10ElementsCorrect()
13+
{
14+
var sequence = new NegativeIntegersSequence().Sequence.Take(10);
15+
sequence.SequenceEqual(new BigInteger[] { -1, -2, -3, -4, -5, -6, -7, -8, -9, -10 })
16+
.Should().BeTrue();
17+
}
18+
}
19+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System.Collections.Generic;
2+
using System.Numerics;
3+
4+
namespace Algorithms.Sequences
5+
{
6+
/// <summary>
7+
/// <para>
8+
/// Sequence of negative integers.
9+
/// </para>
10+
/// <para>
11+
/// Wikipedia: https://wikipedia.org/wiki/Negative_number.
12+
/// </para>
13+
/// <para>
14+
/// OEIS: http://oeis.org/A001478.
15+
/// </para>
16+
/// </summary>
17+
public class NegativeIntegersSequence : ISequence
18+
{
19+
/// <summary>
20+
/// Gets sequence of negative integers.
21+
/// </summary>
22+
public IEnumerable<BigInteger> Sequence
23+
{
24+
get
25+
{
26+
var n = new BigInteger(-1);
27+
28+
while (true)
29+
{
30+
yield return n--;
31+
}
32+
}
33+
}
34+
}
35+
}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ This repository contains algorithms and data structures implemented in C# for ed
104104
* [A000142 Factorial](./Algorithms/Sequences/FactorialSequence.cs)
105105
* [A000578 Cubes](./Algorithms/Sequences/CubesSequence.cs)
106106
* [A001462 Golomb's](./Algorithms/Sequences/GolombsSequence.cs)
107+
* [A001478 Negative Integers](./Algorithms/Sequences/NegativeIntegersSequence.cs)
107108
* [A005132 Recaman's](./Algorithms/Sequences/RecamansSequence.cs)
108109
* [A007318 Binomial](./Algorithms/Sequences/BinomialSequence.cs)
109110
* [A181391 Van Eck's](./Algorithms/Sequences/VanEcksSequence.cs)

0 commit comments

Comments
 (0)