Ejemplo n.º 1
0
    private static Cups PlayTurns(Cups circle, int turnsCount)
    {
        int Prev(int n) => n == 1 ? circle.Count : n - 1;

        for (int i = 0; i < turnsCount; i++)
        {
            var pickedUp    = circle.ExtractNext3();
            var destination = circle.FindNode(Prev(circle.CurrentValue));
            while (pickedUp.Value == destination.Value ||
                   pickedUp.Next.Value == destination.Value ||
                   pickedUp.Next.Next.Value == destination.Value)
            {
                destination = circle.FindNode(Prev(destination.Value));
            }
            circle.InsertRange3(destination, pickedUp);
            circle.MoveNext();
        }
        return(circle);
    }