Problem of the Day
A new programming or logic puzzle every Mon-Fri

Card Storage

Welcome back to Monday! Today's problem comes to us from @hemminga. Thanks for the submission!

In a deck of cards each colour has 13 cards ranging from Ace to 2. A game programmer writes a data structure to denote zero or more different cards in a particular colour. He uses a 13 bit bit-string and flips a bit if a card is in the collection. The Ace in the deck is stored in the first bit, the 2 is stored in the last (thirteenth) bit. The programmer can now convert to a base 10 integer to represent the bit-string and thus the individual cards in that colour.

Example: holding QJ72 in bit-string = 0011000100001 or (1569)base 10

Exercise 1:

Create a function that gives the base 10 integer from any holding of cards in a colour.

Exercise 2:

Convert a base 10 integer to the exact card holding in a colour.

Permalink: http://problemotd.com/problem/card-storage/

Comments:

  • There are currently no comments. You can be first!

Content curated by @MaxBurstein