diff --git a/2020/Day08.cs b/2020/Day08.cs index 4186181..0a39db4 100644 --- a/2020/Day08.cs +++ b/2020/Day08.cs @@ -10,6 +10,8 @@ namespace AdventOfCode { public class Day08 { + public record Instruction(string Op, int Value); + public class GameConsole { int accumulator = 0; int pointer = 0; @@ -44,8 +46,6 @@ namespace AdventOfCode { } } - public record Instruction(string Op, int Value); - public static int RepairBrokenInstruction(List code) { for (int i = 0; i < code.Count(); i++) { if (code[i].Op == "acc") { @@ -65,13 +65,13 @@ namespace AdventOfCode { throw new Exception("didn't find a valid instruction to repair"); } + static Instruction ParseInstruction(string line) { + string[] tokens = line.Split(' '); + return new Instruction(tokens[0], int.Parse(tokens[1])); + } + static List ParseInstructions(string[] code) { - var result = new List(); - foreach (string line in code) { - string[] tokens = line.Split(' '); - result.Add(new Instruction(tokens[0], int.Parse(tokens[1]))); - } - return result; + return code.ToList().Select(ParseInstruction).ToList(); } static int Part1() {