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