Skip to content

Instantly share code, notes, and snippets.

@vdonchev
Created May 19, 2016 20:42
Show Gist options
  • Select an option

  • Save vdonchev/a05c074fa4f54b6b2d84eca9e74a7527 to your computer and use it in GitHub Desktop.

Select an option

Save vdonchev/a05c074fa4f54b6b2d84eca9e74a7527 to your computer and use it in GitHub Desktop.
namespace _05.CalculateSequenceWithQueue
{
using System;
using System.Collections.Generic;
using System.Numerics;
public static class CalculateSequenceWithQueue
{
public static void Main()
{
var queue = new Queue<BigInteger>();
queue.Enqueue(BigInteger.Parse(Console.ReadLine()));
var steps = 0;
while (queue.Count > 0 && steps++ < 50)
{
var num = queue.Dequeue();
Console.Write($"{num} ");
queue.Enqueue(num + 1);
queue.Enqueue((2 * num) + 1);
queue.Enqueue(num + 2);
}
Console.WriteLine();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment