static void Main(string[] args) { var input = "739862541"; var inputValues = input.Select(i => i - '0').ToList(); var circularList1 = new CircularList(9); foreach (var value in inputValues) { circularList1.AddLast(value); } Simulate(circularList1, 100); var answer1 = circularList1.State1; Console.WriteLine($"Answer 1: {answer1}"); var circularList2 = new CircularList(1_000_000); foreach (var value in inputValues) { circularList2.AddLast(value); } var next = circularList2.Max + 1; while (next <= 1_000_000) { circularList2.AddLast(next); next++; } Simulate(circularList2, 10_000_000); var answer2 = circularList2.State2; Console.WriteLine($"Answer 2: {answer2}"); }
static void Simulate(CircularList circularList, int moves) { var min = circularList.Min; var max = circularList.Max; for (int move = 1; move <= moves; move++) { var current = circularList.CurrentItem; var group = circularList.Remove(); var destination = SubtractOne(current, min, max); while (group.Contains(destination)) { destination = SubtractOne(destination, min, max); } circularList.Insert(destination, group); circularList.Rotate(); } }