Skip to content

Instantly share code, notes, and snippets.

@WiredUK
Created December 10, 2015 14:25
Show Gist options
  • Save WiredUK/24dd5796f3ce1bcad9de to your computer and use it in GitHub Desktop.
Save WiredUK/24dd5796f3ce1bcad9de to your computer and use it in GitHub Desktop.
void Main()
{
var input = "1113222113";
Enumerable.Range(1, 50).ToList().ForEach(i =>
{
input = Parse(input);
});
Console.WriteLine($"{input.Length}");
}
private string Parse(string input)
{
var counter = 0;
var ret = new StringBuilder();
var prevChar = input.First();
foreach (var c in input)
{
if (c == prevChar)
{
counter++;
}
else
{
ret.Append(counter.ToString());
ret.Append(prevChar);
counter = 1;
}
prevChar = c;
}
ret.Append(counter.ToString());
ret.Append(prevChar);
return ret.ToString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment