static void GetCrabby(ref Cups cups, int numCups, int numMoves) { int minCup = cups.Min(); int maxCup = cups.Max(); if (numCups > cups.Count) { int cupsToAdd = numCups - cups.Count; cups = new Cups(cups, Enumerable.Range(maxCup + 1, cupsToAdd)); maxCup += cupsToAdd; } LinkedListNode <int> currentCup = cups.First; for (int i = 0; i < numMoves; i++) { //Pick up the next 3 cups for later use List <LinkedListNode <int> > pickedUp = currentCup.CircularRemoveAfter(3).ToList(); //cups.Skip(1).Take(3).ToList(); //Calcluate our destination cup int destination = currentCup.Value; do { destination--; if (destination < minCup) { destination = maxCup; } } while (pickedUp.Select(x => x.Value).Contains(destination)); //Find the destination cup LinkedListNode <int> destinationCup = cups[destination]; //Insert the picked up cups after the destination cup destinationCup.AddAfter(pickedUp); //Move the crab to the next cup for the next move. currentCup = currentCup.CircularNext(); //cups.Next(); } }