Code for the Advent of Code event
aoc
advent-of-code
1using System;
2using System.Text;
3
4public class Program
5{
6 public static void Main()
7 {
8 string input = "1321131112";
9
10 for (int i = 0; i < 40; i++)
11 input = Transform(input);
12
13 Console.WriteLine(input.Length);
14
15 // Do the next 10 to reach 50
16 for (int i = 0; i < 10; i++)
17 input = Transform(input);
18
19 Console.WriteLine(input.Length);
20 }
21
22 private static string Transform(string str)
23 {
24 StringBuilder sb = new StringBuilder();
25
26 int counter = 0;
27 char current = str[0];
28
29 foreach (char c in str)
30 {
31 if (c != current)
32 {
33 sb.Append(counter);
34 sb.Append(current);
35 counter = 0;
36 current = c;
37 }
38
39 counter++;
40 }
41
42 sb.Append(counter);
43 sb.Append(current);
44
45 return sb.ToString();
46 }
47}