Beggar my neighbor, as it is most commonly referred to, is a simple deterministic card game. A standard 52 card deck is shuffled and divided equally between two players. The players keep their 26 card hands face down. The players alternately play their top card face up into a central pool. If an Ace, King, Queen, or Jack appear (penalty cards), the other player must pay the following penalty:
- 4 cards for an Ace
- 3 cards for a King
- 2 cards for a Queen
- 1 card for a Jack
These penalty cards are played face up in the pool one at a time. If while paying the penalty another penalty card is turned up, the player stops paying and the other player must now pay a penalty. This switching of payment may occur many times. Eventually when one player has paid the full penalty and the last payment card is not a penalty card, the pool is awarded to the player who last laid down a penalty card. That player takes the pool, turns it face down, and adds it to the bottom of their hand. Play continues until one player has all 52 cards.
Let's go through an example starting sequence:
- P1 starts by playing a three
- P2 plays a queen -> P1 must pay a penalty of two cards
- P1 plays a seven, then a jack -> P2 must pay a penalty of one card
- P2 plays a two -> penalty has been paid in full, P1 takes pool (5 cards) and continues play.
This game still has open questions in combinatorial game theory. For example it is unknown what the longest possible finite game is in terms of total cards played. As of February 2024, the longest known finite game terminated with 8344 cards played and 1164 pools won. There are quite a few starting hands for a standard 52 card deck that produce infinitely long games. Shown below are some histograms of my 100,000 game simulation. Note the exponential probability distribution of game length.
Write a function that will take two 26 card hands and who begins play (1 or 2) and return the winner (1 or 2), how many cards were played, and how many pools were won. The hands will be given as a vector of card penalty values (cards 2-10 are 0, jacks are 1, queens are 2, kings are 3, and aces are 4). The first card in the vector is the top card.
Solution Stats
Problem Comments
2 Comments
Solution Comments
Show comments
Loading...
Problem Recent Solvers2
Suggested Problems
-
Play Games of Beggar My Neighbor
2 Solvers
More from this Author5
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
Nice problem, Matthew.
For everyone else who wants to solve this: the "stack" and "pool" are the same, while each player's own "stack" is their hand. Also, whenever any player is unable to play a card, the other player wins the pool, and then immediately wins on account of having 52 cards in their hand.
Thanks, Christian! I altered the terminology to be a bit less confusing. The original game calls the center pools "tricks" for some reason haha