Skip to content

Instantly share code, notes, and snippets.

@johnboker
Created December 10, 2015 14:01
Show Gist options
  • Save johnboker/79de0018323efbcc05d7 to your computer and use it in GitHub Desktop.
Save johnboker/79de0018323efbcc05d7 to your computer and use it in GitHub Desktop.
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