1 Star 0 Fork 0

jobily/TheAlgorithms-C-Sharp

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
.github
Algorithms.Tests
Algorithms
Crypto
DataCompression
Encoders
Graph
Knapsack
LinearAlgebra
ModularArithmetic
Numeric
Other
Problems
Search
Sequences
AllOnesSequence.cs
AllThreesSequence.cs
AllTwosSequence.cs
BinaryPrimeConstantSequence.cs
BinomialSequence.cs
CakeNumbersSequence.cs
CatalanSequence.cs
CentralPolygonalNumbersSequence.cs
CubesSequence.cs
DivisorsCountSequence.cs
EuclidNumbersSequence.cs
EulerTotientSequence.cs
FactorialSequence.cs
FermatNumbersSequence.cs
FermatPrimesSequence.cs
FibonacciSequence.cs
GolombsSequence.cs
ISequence.cs
KolakoskiSequence.cs
KolakoskiSequence2.cs
KummerNumbersSequence.cs
LucasNumbersBeginningAt2Sequence.cs
MakeChangeSequence.cs
MatchstickTriangleSequence.cs
NaturalSequence.cs
NegativeIntegersSequence.cs
NumberOfBooleanFunctionsSequence.cs
NumberOfPrimesByNumberOfDigitsSequence.cs
NumberOfPrimesByPowersOf10Sequence.cs
OnesCountingSequence.cs
PowersOf10Sequence.cs
PowersOf2Sequence.cs
PrimePiSequence.cs
PrimesSequence.cs
PrimorialNumbersSequence.cs
RecamansSequence.cs
SquaresSequence.cs
TetrahedralSequence.cs
TetranacciNumbersSequence.cs
ThreeNPlusOneStepsSequence.cs
TribonacciNumbersSequence.cs
VanEcksSequence.cs
ZeroSequence.cs
Shufflers
Sorters
Stack
Strings
Algorithms.csproj
NewtonSquareRoot.cs
DataStructures.Tests
DataStructures
Utilities.Tests
Utilities
.editorconfig
.gitignore
C-Sharp.sln
CODE_OF_CONDUCT.md
CONTRIBUTING.md
LICENSE
README.md
stylecop.json
stylecop.ruleset
克隆/下载
MakeChangeSequence.cs 1.64 KB
一键复制 编辑 原始数据 按行查看 历史
using System.Collections.Generic;
using System.Numerics;
namespace Algorithms.Sequences;
/// <summary>
/// <para>
/// Number of ways of making change for n cents using coins of 1, 2, 5, 10 cents.
/// </para>
/// <para>
/// OEIS: https://oeis.org/A000008.
/// </para>
/// </summary>
public class MakeChangeSequence : ISequence
{
/// <summary>
/// <para>
/// Gets sequence of number of ways of making change for n cents
/// using coins of 1, 2, 5, 10 cents.
/// </para>
/// <para>
/// Uses formula from OEIS page by Michael Somos
/// along with first 17 values to prevent index issues.
/// </para>
/// <para>
/// Formula:
/// a(n) = a(n-2) +a(n-5) - a(n-7) + a(n-10) - a(n-12) - a(n-15) + a(n-17) + 1.
/// </para>
/// </summary>
public IEnumerable<BigInteger> Sequence
{
get
{
var seed = new List<BigInteger>
{
1, 1, 2, 2, 3, 4, 5, 6, 7, 8,
11, 12, 15, 16, 19, 22, 25,
};
foreach (var value in seed)
{
yield return value;
}
for(var index = 17; ; index++)
{
BigInteger newValue = seed[index - 2] + seed[index - 5] - seed[index - 7]
+ seed[index - 10] - seed[index - 12] - seed[index - 15]
+ seed[index - 17] + 1;
seed.Add(newValue);
yield return newValue;
}
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/hubo/the-algorithms-c-sharp.git
git@gitee.com:hubo/the-algorithms-c-sharp.git
hubo
the-algorithms-c-sharp
TheAlgorithms-C-Sharp
master

搜索帮助