Hand and Foot

Hand and Foot is a card game. The object of the game is to get the most points. Points are awarded by creating groups of cards with like values (e.g. all 4's) called "books" 📕. 3's don't participate in books 📕. During their turn, a player draws 2 cards, works on their books, and then must discard 1 card.

In the variation played in my family, when points are totaled at the end of the game, black ♠️♣️ 3's in hand deduct 0 points while red ♥️♦️ 3's deduct 300 points. To free up their hand and mind, players often create a pile for their 3's, since they generally are the first choice for discarding. Without a system to the pile, when the time comes to discard, a player must search the pile for a red ♥️♦️ 3. Ask me how I know 🤦‍♂️.

Here's where a data structure and algorithm come in very handy 💡. If a player adds red ♥️♦️3's to the top of the pile and black ♠️♣️ 3's to the bottom, discarding the top card will always reduce the count of red ♥️♦️3's until none are left!

What I've described is known as a double-ended queue since:

  • red ♥️♦️3's are inserted on the top ⬆️

  • black ♠️♣️ 3's are inserted on the bottom ⬇

with output-restricted dequeue (only dequeue from the top ⬆️).

See https://en.wikipedia.org/wiki/Double-ended_queue for more details.

Did you find this article valuable?

Support Brett Rowberry’s Blog by becoming a sponsor. Any amount is appreciated!