Skip to content

Commit 1c465ec

Browse files
authored
Add A001146 Number of Boolean Functions sequence (TheAlgorithms#297)
1 parent 0891a9c commit 1c465ec

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-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 NumberOfBooleanFunctionsSequenceTests
10+
{
11+
[Test]
12+
public void First5ElementsCorrect()
13+
{
14+
var sequence = new NumberOfBooleanFunctionsSequence().Sequence.Take(5);
15+
sequence.SequenceEqual(new BigInteger[] { 2, 4, 16, 256, 65536 })
16+
.Should().BeTrue();
17+
}
18+
}
19+
}
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 number of truth tables generated by Boolean expressions of n variables
9+
/// (Double exponentials of 2: a(n) = 2^(2^n)).
10+
/// </para>
11+
/// <para>
12+
/// Wikipedia: https://wikipedia.org/wiki/Truth_table.
13+
/// </para>
14+
/// <para>
15+
/// OEIS: https://oeis.org/A001146.
16+
/// </para>
17+
/// </summary>
18+
public class NumberOfBooleanFunctionsSequence : ISequence
19+
{
20+
/// <summary>
21+
/// Gets sequence of number Of Boolean functions.
22+
/// </summary>
23+
public IEnumerable<BigInteger> Sequence
24+
{
25+
get
26+
{
27+
var n = new BigInteger(2);
28+
29+
while (true)
30+
{
31+
yield return n;
32+
n *= n;
33+
}
34+
}
35+
}
36+
}
37+
}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ This repository contains algorithms and data structures implemented in C# for ed
108108
* [A000290 Squares](./Algorithms/Sequences/SquaresSequence.cs)
109109
* [A000578 Cubes](./Algorithms/Sequences/CubesSequence.cs)
110110
* [A000720 PrimePi](./Algorithms/Sequences/PrimePiSequence.cs)
111+
* [A001146 Number of Boolean Functions](./Algorithms/Sequences/NumberOfBooleanFunctionsSequence.cs)
111112
* [A001462 Golomb's](./Algorithms/Sequences/GolombsSequence.cs)
112113
* [A001478 Negative Integers](./Algorithms/Sequences/NegativeIntegersSequence.cs)
113114
* [A002110 Primorial Numbers](./Algorithms/Sequences/PrimorialNumbersSequence.cs)

0 commit comments

Comments
 (0)