Created
December 10, 2015 14:01
-
-
Save johnboker/79de0018323efbcc05d7 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
using System; | |
using System.Linq; | |
using System.Text; | |
namespace AdventOfCodeDay10 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var input = "1321131112"; | |
for (var i = 0; i < 50; i++) | |
{ | |
input = LookAndSay(input); | |
if (i + 1 == 40 || i + 1 == 50) | |
{ | |
Console.WriteLine($"{i + 1} : {input.Length}"); | |
} | |
} | |
Console.ReadLine(); | |
} | |
private static string LookAndSay(string input) | |
{ | |
var sb = new StringBuilder(); | |
var current = input.First(); | |
var count = 0; | |
foreach (var c in input) | |
{ | |
if (c == current) | |
{ | |
count++; | |
} | |
else | |
{ | |
sb.Append($"{count}{current}"); | |
current = c; | |
count = 1; | |
} | |
} | |
sb.Append($"{count}{current}"); | |
return sb.ToString(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment