Skip to content

Instantly share code, notes, and snippets.

@EBojilova
Created April 10, 2015 20:23
Show Gist options
  • Save EBojilova/8dfab658f536e8156330 to your computer and use it in GitHub Desktop.
Save EBojilova/8dfab658f536e8156330 to your computer and use it in GitHub Desktop.
using System;
class GameOfBits
{
static void Main(string[] args)
{
uint number = uint.Parse(Console.ReadLine());
//Console.WriteLine(Convert.ToString(number, 2).PadLeft(32, '0'));
string command;
uint count1 = 0;
while (!(string.IsNullOrEmpty(command = Console.ReadLine()) || command == "Game Over!"))
{
uint newNum = 0;
uint currentNum = 0;
count1 = 0;
if (command == "Even")
{
number >>= 1;
}
for (int i = 0, iNew = 0; i < 32; i += 2, iNew++)
{
currentNum = (number >> i) & 1;
count1 += currentNum;
newNum |= currentNum << iNew;
}
number = newNum;
//Console.WriteLine(Convert.ToString(number, 2).PadLeft(32, '0'));
}
Console.WriteLine("{0} -> {1}", number, count1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment