Created
December 10, 2015 14:25
-
-
Save WiredUK/24dd5796f3ce1bcad9de to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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