40
$\begingroup$

At a party last night, my friends Alice and Bob did a magic trick. Any ideas how it worked?

Alice shuffled a pack of cards, and asked me to take five. I looked at them. She put the rest of the pack down on the table. Alice asked for my cards. She gave four of them to Bob (he was across the table), and the fifth back to me. Bob looked at the four cards for a while. Then Bob looked at me, and named the card I was holding. He was right. I'm quite sure he couldn't have seen it (we weren't sitting by a mirror).

They did the trick again later to someone else. I watched for funny business. Alice didn't say anything to Bob, so I don't think they have a code. Also Alice is famously clumsy, so I doubt it was sleight of hand.


Edit to answer a question: I learnt the trick from a maths magazine several years ago. I don't know who invented it. "Michael Kleber. The best card trick. Mathematical Intelligencer 24 #1 (Winter 2002)"

$\endgroup$
  • 1
    $\begingroup$ (I know how the trick works, but the exposition is more fun this way. I don't have a friend called Alice either.) $\endgroup$ – Colonel Panic Dec 31 '14 at 17:47
  • 2
    $\begingroup$ did Alice look at the cards when deciding which 4 to give to Bob? $\endgroup$ – Kate Gregory Dec 31 '14 at 17:53
  • 1
    $\begingroup$ @KateGregory yes she took a while actually. $\endgroup$ – Colonel Panic Dec 31 '14 at 19:09
  • 1
    $\begingroup$ @ColonelPanic thanks, but I think it should be edited into to OP to comply with the site's copyright policy. $\endgroup$ – BmyGuest Jan 1 '15 at 19:24
  • 1
    $\begingroup$ This question was used in Paypal's interviews quora.com/What-s-the-hardest-puzzle-question-asked-at-PayPal/… $\endgroup$ – Pacerier Nov 11 '15 at 1:56
34
$\begingroup$

I'm going to assume Alice looked at the cards and chose which one to give back to you. The key to the puzzle is then to encode a single card's suit and value in 4 cards without the luxury of choosing those 4 cards arbitrarily from the whole deck.

The suit is easy. In 5 cards there must be a double of at least one suit. So the first (or last, but I'll choose arbitrarily) card in the bunch she passes is the same suit as yours. Now there are three cards left to encode a number from 1 to 13. However Alice chose which card of your suit to pass to Bob and which to return to you. She can choose according to a rule that gets the number of possible cards down significantly.

The three passed cards can be designated small medium and large according to their number, and then breaking ties by suit order (clubs smallest, diamonds, hearts, spades as in bridge.) This gives six possible numbers to be represented by the 3 passed cards based on their order: SML, SLM, MLS, MSL, LSM, LMS.

So how does she choose which of the suit cards to pass and which to return? Bob will add the encoded number to the passed card (going around K-A-2 if need be) to get the returned card. Alice passes whichever card is within an add of 6.

Say you have the 2 and 4 of spades in your 5. She can't pass the 4 because no number between 1 and 6, added to 4, will wrap around to the 2. So she passes the 2 and encodes 2 in the other three cards by ordering them SLM. If you have the Q and K she passes the Q and encodes 1. If you have the 7 and K she passes the 7 and encodes 6. But 6 and K, she passes the K and encodes 6.

I've tried to find a set of cards you could choose, knowing this algorithm, that would make it impossible to perform the trick, and I can't. Not from a proper deck that doesn't have any duplicate cards.

$\endgroup$
  • $\begingroup$ That's exactly the code I use: First card gives suit and starting number. Next three cards give an offset between 1 and 6, according to lexicographic permutation. You can teach it to a friend in a few minutes. People tend to get confused when the cards tie, but you can usually avoid it by changing your choice of fifth card. $\endgroup$ – Colonel Panic Jan 2 '15 at 16:11
  • $\begingroup$ @ColonelPanic If this is an acceptable answer, the OP should state that Alice both looked at the cards and rearranged them, before handing them to Bob. $\endgroup$ – eclipz905 Jan 2 '15 at 16:32
  • $\begingroup$ @eclipz905 Alice could conceal the re-ordering by pulling one card at a time from the 5 and passing them over, retaining the 5th to return to the mark. $\endgroup$ – Kate Gregory Jan 2 '15 at 17:29
  • $\begingroup$ @KateGregory I would be happier to accept that if the OP did not have the segment about seeing the trick performed again. Stealthy reordering the cards would constitute sleight of hand. $\endgroup$ – eclipz905 Jan 2 '15 at 17:52
  • $\begingroup$ I don't understand the suits. What if your chosen card was not a double? $\endgroup$ – Jay Sep 9 '18 at 7:11
16
$\begingroup$

Here is my answer:

  • Key Item 1:

    In a deck there are 52 cards of which 4 are with Bob. So Bob needs to determine the unknown from 48 cards.

  • Key Item 2:

    Given 4 ordered cards, the number of ways to arrange it in ascending order is 4! = 24

  • Key Item 3:

    The hand can have two orientations, upright and reversed. So no of arrangements = 2*4! = 48

  • Key Item 4:

    Let Alice encode the remaining 48 cards following a strict ordering of suits ♣ < ♦ < ♥ < ♠ and number Ace, Two ..,Ten, Jack, Queen, King and taking into consideration of the missing 4 cards

  • Key Item 5:

    Bob, aware of Alice's strategy, decodes the arrangement of the cards back to the index of the cards strictly ordered based on suits and numbers.

$\endgroup$
  • $\begingroup$ Using the reversing of cards as an additional code is interesting - but Kate Gregory's solution doesn't require it (by looking for the "shorter distance" between the two cards of the same suit). And if reversing is an option, you don't just have 2, but 2*2*2*2 additional combinations surely? Perhaps she could just hand Bob the four cards all face-up or face-down to achieve what you are taking about - it would be less conspicuous. $\endgroup$ – Floris Jan 1 '15 at 21:23
  • $\begingroup$ @Floris: To simplify reversing here would mean reversing the entire hand or none. This gives you a space of 24 cards to search. Moreover, I have never said my solution is elegant. Just thought of independently as I have never heard about this trick before. :-) $\endgroup$ – Abhijit Jan 2 '15 at 6:38
  • 1
    $\begingroup$ Actually I thought your solution (in particular, the approach to the solution) was very elegant: you actually calculated whether it would be possible to encode, and came up with an independent solution. Which is why yours was the solution I upvoted. I was just asking for clarification - deck up/down, or individual cards. I think you confirmed it was deck up/down. $\endgroup$ – Floris Jan 2 '15 at 13:42
11
$\begingroup$

This is a great card trick known as Fitch Cheney's Five Card trick. Alice selects the fifth card to be identified and arranges the remaining four cards in a specific sequence. Then Bob interprets the four card sequence and identifies the fifth card.

Here are a few references that describe how to sequence the four cards:
Batman on wordpress
Gray Matters on blogspot

And here is Bob and Alice doing the trick again ;-)

$\endgroup$
6
$\begingroup$

From the point of view of Charlie (the one who holds the card to be identified and verifies Bob's answer), a trick when Charlie himself pulls the card from Alice's hands will look more showy.

To make this possible-

we need to be able to encode any one of 52-4=48 cards. The four cards can encode any pair of 4!=24 pairs of cards (thus covering all 48 cards), therefore we need to send Bob an extra bit of information (pointing to a single card in the pair of cards identified by the four cards). We can pass this single bit with any secret sign (with sight, head, elbow movement, orientation of cards on the table etc.)

Neither base card, nor offset is used with encoding. Any one of 52-4=48 cards is encoded with one of 2*4!=48 possible states. Here 4! states are covered by the four cards, and 2 possible states (a single bit) are covered with a secret sign.

The way we encode is similar to the one described by Kate Gregory. If the smallest card of the four is A, the next bigger one is B, then C, and the biggest one is D, we can encode each of the rest 24 pairs of cards like ABCD, ABDC, ACBD, ACDB, ADBC, ADCB, BACD, BADC, BCAD, BCDA, BDAC, BDCA, CABD, CADB, CBAD, CBDA, CDAB, CDBA, DABC, DACB, DBAC, DBCA, DCAB, DCBA.

Another method is when Alice asks Charlie to take six cards and then asks him to pull one, while the other five provide redundant space to encode any card (with one of 52-5=47 useful states among 5!=120 possible states).

$\endgroup$
  • $\begingroup$ but say the 5 cards are two spades, one diamond, one heart, and one club. How can Alice ensure that Charlie pulls a spade, and furthermore a spade the right distance from the spade left behind? Without explaining that mechanism this isn't really an answer. $\endgroup$ – Kate Gregory Jan 2 '15 at 19:03
  • $\begingroup$ Alice doesn't need to ensure. Whatever card is pulled by Charlie, it is identified from the information passed with the other cards (four cards [out of five] plus a secret sign carrying a single bit, or five cards [out of six]). $\endgroup$ – user3900460 Jan 2 '15 at 20:45
  • $\begingroup$ There is no base card and no offset. Any one of 52-4=48 cards can be encoded with 2*4!=48 states (4! is passed with the four cards, and 2 (i.e. a single bit) is passed with a secret sign), or with 5! states (if we use 6 cards and pass 5 of them to Bob), without a secret sign. $\endgroup$ – user3900460 Jan 2 '15 at 21:03
  • 2
    $\begingroup$ @user3900460 This is a magnificent answer, alternative to the usual one. IMHO the most fitting way of passing a bit, with regard to the story, is whether she passes the cards facing upwards or downwards. $\endgroup$ – dmg Jan 6 '15 at 10:02
3
$\begingroup$

Wanted to point out that the classic solution is just the most "human" way of doing this and while we humans tend to appreciate things that are easy for us, the classic technique is wasteful and there is another generic solution that came to me while observing the problem.

(1) Enumerate all cards with indices ranging from 0 to 51. It does not matter how you order the playing cards.

(*) Now we have five unique integers within the range. We need to discard one in a way that is easily reversible.

(2) We sum them all up and get a new integer S and we use modulo 5 to decide which card (integer) to omit. Lets call S modulo 5 j.

(3) We will rank (order) the cards from the lowest to the highest and omit the card with rank j.
(*) Good. Now that we have 4 integers left, we consider all the sets of 5 integers that would have ended with these 4.

(4) To do this we can quickly iterate over all the missing integers and check which ones fit. There should be about ~10 that fit.

(5) There are 24 way to order the remaining 4 cards and there are less than a dozen options. We order these options from lowest to highest and order the cards accordingly. Assuming the cards are ranked from lowest to highest, you"ll have 24 available permutations:

1234, 1243, 1324, 1342 ... 4231, 4312, 4321

Of course this is harder to do cause it is not human friendly but it is much more efficient and generic so it should work with any set of integers and any number of integers where such a bijection exists.

$\endgroup$
  • $\begingroup$ Of course, there are a myriad ways humans can signal the index of the fifth card but I suspect this wasn't the intention in this riddle. The only tools available are the order and the choice to omit a specific card. Otherwise you could signal the card with a grin, a frown, wiping your nose or scratching your head. $\endgroup$ – wolfdawn Dec 12 '16 at 20:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.