Skip to content

Commit c17adda

Browse files
authored
Add A011557 Powers of 10 sequence (TheAlgorithms#289)
1 parent d73ae5f commit c17adda

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-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 PowersOf10SequenceTests
10+
{
11+
[Test]
12+
public void First10ElementsCorrect()
13+
{
14+
var sequence = new PowersOf10Sequence().Sequence.Take(10);
15+
sequence.SequenceEqual(new BigInteger[]
16+
{ 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 })
17+
.Should().BeTrue();
18+
}
19+
}
20+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Collections.Generic;
2+
using System.Numerics;
3+
4+
namespace Algorithms.Sequences
5+
{
6+
/// <summary>
7+
/// <para>
8+
/// Sequence of powers of 10: a(n) = 10^n.
9+
/// </para>
10+
/// <para>
11+
/// Wikipedia: https://wikipedia.org/wiki/Power_of_10.
12+
/// </para>
13+
/// <para>
14+
/// OEIS: https://oeis.org/A011557.
15+
/// </para>
16+
/// </summary>
17+
public class PowersOf10Sequence : ISequence
18+
{
19+
/// <summary>
20+
/// Gets sequence of powers of 10.
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+
n *= 10;
32+
}
33+
}
34+
}
35+
}
36+
}

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
* [A005132 Recaman's](./Algorithms/Sequences/RecamansSequence.cs)
110110
* [A006880 Number of Primes by Powers of 10](./Algorithms/Sequences/NumberOfPrimesByPowersOf10Sequence.cs)
111111
* [A007318 Binomial](./Algorithms/Sequences/BinomialSequence.cs)
112+
* [A011557 Powers of 10](./Algorithms/Sequences/PowersOf10Sequence.cs)
112113
* [A181391 Van Eck's](./Algorithms/Sequences/VanEcksSequence.cs)
113114
* [String](./Algorithms/Strings)
114115
* [Longest Consecutive Character](./Algorithms/Strings/GeneralStringAlgorithms.cs)

0 commit comments

Comments
 (0)