You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/// Van Eck's sequence. For n >= 1, if there exists an m < n such that a(m) = a(n), take the largest such m and set a(n+1) = n-m; otherwise a(n+1) = 0. Start with a(1)=0.
/// </para>
/// <para>
/// OEIS: http://oeis.org/A181391.
/// </para>
/// </summary>
public class VanEcksSequence : ISequence
{
/// <summary>
/// Gets Van Eck's sequence.
/// </summary>
public IEnumerable<BigInteger> Sequence
{
get
{
yield return 0;
var dictionary = new Dictionary<BigInteger, BigInteger>();
BigInteger previous = 0;
BigInteger currentIndex = 2; // 1-based index
while (true)
{
BigInteger element = 0;
if (dictionary.TryGetValue(previous, out var previousIndex))