Solitaire card games/Perpetual Motion

Rules
The tableau is made up of four piles/columns. Four cards are dealt (the rest are left aside as the stock), one in each pile. If there are cards of equal rank (such as three kings), the duplicates are moved to the leftmost pile with an equal card.

Example: The three kings mentioned are found at piles 2, 3, and 4. The kings in piles 3 and 4 are moved to pile 2.

After that, four cards are again dealt from the stock (even if one pile is empty) and plays already mentioned are made. Only the top card of each pile is in play. In case the four cards dealt from the stock are all of the same rank, they are immediately discarded.

This continues until the stock runs out. After this first round, the piles are picked up, starting from the rightmost pile, and put over one another either faced down or face up without disturbing the order of the cards in each pile. Four cards are again dealt and the steps mentioned earlier are again done.

The game is won when all cards are discarded (in fours). This is not always possible, however, since in about 45% of cases a cycle occurs: that is, the cards return to exactly the same sequence as one that has been seen previously. When the game can be won, it still takes an average of 128 rounds before completion, hence the name.

Idiot's Delight (Alternate Rules)
An alternate way to play, as suggested by Peter Drake in his book "Data Structures and Algorithms in Java", is as follows:

The object is still to remove all the cards from the table, but the methods are slightly different.

Play begins by dealing four cards into four separate stacks, one card in each stack. The rest of the cards are kept aside as stock. A player may do one of three things:


 * If there are two cards of the same rank showing, discard both of them
 * If there are two cards of the same suit showing, discard the one with the lower rank
 * If neither of those conditions exist, deal four new cards, one on top of each stack.

Similar to perpetual motion, this continues until the stock runs out and no more removals can be made.

Games will obviously end much sooner than with Perpetual Motion, but considering that the game can only end if the last two cards are of the same rank, the odds of winning are not in the player's favour.