namespace Day8; public class MapData { public string Instructions { get; } public Node Start { get; } public MapData(string instructions, Node start) { Instructions = instructions; Start = start; } public long Walk() { var current = Start; var steps = 0L; while (current.Name != "ZZZ") { if (steps >= 1000000) { throw new Exception("Over ONE MILLION"); } var instruction = Instructions[(int)(steps % Instructions.Length)]; if (instruction != 'L' && instruction != 'R') { throw new Exception($"Unknown instruction: {instruction} @ {steps}"); } Console.WriteLine($"{current.Name} => {instruction}"); steps++; current = instruction == 'L' ? current.Left : current.Right; if (current == null) { throw new Exception($"Ended in null after: {instruction} @ {steps}"); } } return steps; } }