Hand and Foot

Brett RowberryBrett Rowberry
2 min read

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.

0
Subscribe to my newsletter

Read articles from Brett Rowberry directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Brett Rowberry
Brett Rowberry

I like programming (at work) and learning for fun. You'll often find me cooking and working on my house in my spare time.