public string SolvePart2(string input, IProgress <string> progress = null) { Parse(input); while (true) { if (Carts.Count(c => !c.Crashed) == 1) { var cart = Carts.First(c => !c.Crashed); return((cart.X, cart.Y).ToString()); } foreach (var cart in Carts.OrderBy(c => c.Y).ThenBy(c => c.X)) { if (cart.Crashed) { continue; } var next = cart.GetNextLocation(); var otherCart = Carts.FirstOrDefault(c => !c.Crashed && c.X == next.x && c.Y == next.y); if (otherCart != null) { cart.Crashed = true; otherCart.Crashed = true; } char track = LookAhead(cart); switch (cart.Direction) { case Direction.Up: cart.Y--; switch (track) { case '\\': cart.Direction = Direction.Left; break; case '/': cart.Direction = Direction.Right; break; case '+': IntersectionTurn(cart); break; } break; case Direction.Down: cart.Y++; switch (track) { case '\\': cart.Direction = Direction.Right; break; case '/': cart.Direction = Direction.Left; break; case '+': IntersectionTurn(cart); break; } break; case Direction.Left: cart.X--; switch (track) { case '\\': cart.Direction = Direction.Up; break; case '/': cart.Direction = Direction.Down; break; case '+': IntersectionTurn(cart); break; } break; case Direction.Right: cart.X++; switch (track) { case '\\': cart.Direction = Direction.Down; break; case '/': cart.Direction = Direction.Up; break; case '+': IntersectionTurn(cart); break; } break; default: throw new ArgumentOutOfRangeException(); } } } }