The hidden card

867.2K Views

In this problem, you and a partner are to come up with a scheme for communicating the value of a hidden card.  The game is played as follows:

  • Your partner is sent out of the room.
  • A dealer hands you 5 cards from a standard 52 card deck.
  • You look at the cards, and hand them back to the dealer, one by one, in whatever order you choose.
  • The dealer takes the first card that you hand her and places it, face up, in a spot labeled “0”‘.  The next three cards that you hand her, she places, similarly, in spots labeled “1”, “2”, and “3”.  The last card that you hand her goes, face down, in a spot labeled “hidden”.  (While you control the order of the cards, you have no control over their orientations, sitting in their spots; so you can’t use orientation to transmit information to your partner.)
  • Your partner enters the room, looks at the four face-up cards and the spots in which they lie and, from that information (and your previously-agreed-upon game plan), determines the suit and value of the hidden card.

Question: What is the foolproof scheme that you and your partner settled on ahead of time?

As a follow-up question, consider the same problem but with a 124-card deck.

Share
ronret45 Expert Asked on 1st August 2015 in Microsoft Interview Puzzles.
Add Comment

  • 1 Answer(s)

    Initial Thoughts:

    Initially, this problem seems very intimidating because the idea that any four cards could be “encoded” to reveal another card is a bit crazy. One of the first things, I realized was that since you have 5 cards and there are 4 distinct suits, each hand will have at least one duplicate suit.

    In order to obtain the value of the card, I thought I could use the 4 spots in indicate a 4-bit number, this would give us all numbers up to 15! Since we only needed numbers 1-13, I thought this was a really good option, however I couldn’t find a way to give my partner the suit of the hidden card with this option.

    The Main  Solution:

    My solution ended up being a modification of my Initial Thoughts. Since there is always at least one duplicate suit in a hand of 5, I will always choose a card that has a corresponding duplicate suit for the face down card, and the card with the same suit will go in the “0” position.

    In order to obtain the value of the card, we can only use the last 3 spots, so with our original thought of using base 2, we can communicate numbers 1-7.

    We always have three cards is spots “1”, “2”, and “3”, so the rule I came up with involves assigning “1”‘s to spots where the current card is greater than the card preceding it, and “0” otherwise Let’s say we have cards 1, 2, 3 ordered by rank.

    If we wanted to display the value 3, our card order would be 231.

    • 2 is in the “one” position and has no preceding number, so we will look at the number in the “three” position, and see that 2 is greater than 1, so our string is “1”.
    • 3 is in the “two” position and is greater than 2, which is in the “one” position, so our string is “11”
    • 1 is in the “three” position and is less than 3, which is in the “two” position, so our final string is “110”.

    110 is binary for 3, so we have just represented the value of 3 to our partner.

    How could we show if the value of the hidden card was 8 or greater?

    The answer is: We don’t need to. Since there are 13 values in a deck, the difference between any two cards will always be 6 or less.

    You may be thinking, well what about 2 and K?! The difference between these two cards is 11! True, if you go from 2 -> K. But if you go from K -> 2, the difference is only 2! (K-> A -> 2). This means that it is important that the first face up card you pick has an absolute difference of 6 or less from the last card you pick, along with the same suit. Any two card values will always have one.

    For example: If you have 2♠,  9♠, K♦, 3♥, A♣. You would hand the dealer the cards in this order: 9♠, 3♥, K♦, A♣, 2♠(face down). My partner would see that that suit is ♠. Using the base 2 pattern on (3♥, K♦, A♣), we can get the value “011” which is 6. By adding our value 6 to 9♠ we see that we get 2 (9 -> 10 -> J -> Q -> K -> A -> 2). Thus our face down card is the 2♠, and my partner and I have stumped the dealer.

    In this situation we assume that A is the highest of the the values, but this can always be changed around.

    You might be wondering what we would do if we had duplicate value of the card. What if our hand was 5♠, 10♠, 5♦, 5♥, 5♣ ?!

    We got 4 cards with all the same value! The simple solution to this is to create a suit ordering. My personal preference is ♣(clubs), ♠(spades), ♥(hearts), ♦ (diamonds), but you and your partner can choose any order you want.

    So, we would hand the dealer the cards in this order: 5♠, 5♦, 5♣,5♥,10♠(face down). So we would see that our starting suit is ♠, and starting value is 5. (5♦, 5♣,5♥) will translate to “101” because (♥ < ♦) , (♦ > ♣), and (♣ < ♥), and we have communicated the value of 5. So we add 5 to our starting value and see our answer is 10♠. Sorry dealer, no tricks with our plan.

    Here we can ignore the values and look only at the suits since they are all the same.

    This works because a deck of 52 cards has no duplicates, so the deck has an exact ordering.

    ronit Guru Answered on 5th August 2015.
    Add Comment
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.
  • More puzzles to try-