# Interesting math card trick, would like some insight on how it works

I watched a video explaining a card trick today, there were no tricks, it was all based on math.
Here's the set up:

52 cards in the deck. person A takes some of them, then person B takes some as well.

The dealer counts the remaining cards in his hand, say he has 18.

Then he says he'll make a prediction. he does these calculations in his head: 1 + 8 = 9, and 16-9=7. So he looks through his cards and pulls out a seven, and sets it aside face down. (persons A and B are unaware of what the card is)

Then person A counts the cards in his hand, suppose he has taken 19. The dealer says 1+9=10 and 1+0=1, so person A has a 1.

Person B counts his cards, and he has 15. So he says then that 1 + 5 = 6, so person B has a 6.

Then he says that since person A has a 1, and person B has a 6, that his card is 1+6 = 7, and flips over his 7 to end the trick.

I find this trick to be truly fascinating. I have no idea how to begin answering why this trick works. Anyone care to try and offer an explanation?

I watched a video explaining a card trick today, there were no tricks, it was all based on math.
Here's the set up:

52 cards in the deck. person A takes some of them, then person B takes some as well.

The dealer counts the remaining cards in his hand, say he has 18.

Then he says he'll make a prediction. he does these calculations in his head: 1 + 8 = 9, and 16-9=7. So he looks through his cards and pulls out a seven, and sets it aside face down. (persons A and B are unaware of what the card is)

Then person A counts the cards in his hand, suppose he has taken 19. The dealer says 1+9=10 and 1+0=1, so person A has a 1.

Person B counts his cards, and he has 15. So he says then that 1 + 5 = 6, so person B has a 6.

Then he says that since person A has a 1, and person B has a 6, that his card is 1+6 = 7, and flips over his 7 to end the trick.

I find this trick to be truly fascinating. I have no idea how to begin answering why this trick works. Anyone care to try and offer an explanation?
It's just the old trick of "casting out 9's," and it's easily understood using modular arithmetic.

First, what is the remainder when 52 is divided by 9? Well, 9*6 = 45, so the remainder is 7.

Now when you add up the digits of a number and then add its digits, etc., until you're left with a 1-digit answer, you always get the remainder when you divide the original number by 9. That's called "casting out 9's,", and it's an artifact of our base-10 numbering system. In base 8, you can "cast out 7's" for example.

Try it. For example try 12345. Well 1+2+3+4+5 = 15 = 9 + 6, so the remainder when 15's divided by 9 is 6. And if you type "12345 mod 9" into Google, it gives you 6. Isn't the Internet great? In the old days we had to figure that out with pencil and paper!

Ok so back to the card problem. If D is the number of cards the dealer has left after A and B are done, then A+B+D = 52, so A+B = 52-D.

Now the dealer replaces the 52 with the number 16 on the right side of the equation. Why can he do that? Because we only care about remainders, and 52 and 16 have the same remainder when divided by 9 (namely 7). So we have

$A+B \equiv 16-D$ (mod 9)

where the notation $x \equiv y$ (mod 9) means that the left and right side have the same remainder upon division by 9. We say that "x and y are equivalent mod 9" or "x and y are congruent mod 9." All it means is that they have the same remainder when you divide them by 9.

When we cast out 9's from both sides, equivalence (mod 9) is preserved. As I said earlier, if we add up the digits of a number, the result is equivalent (mod 9) to the original number.

So the sum of the number of A's and B's cards is equivalent, mod 9, to 16 minus the number of the dealer's cards. And when we cast out 9's (add the digits), the equivalence is preserved.

Here's another example. A takes 10, B takes 22. The dealer has 30. The dealer adds 3+0 = 3, then calculates 16 - 3 = 13; then adds 1+3 = 4. And how about that, that's what you get when you cast out 9's on the left: $10+12 = 22 \equiv 4$ (mod 9).

If I made this too complicated, it's because I was trying to make it simple by trying to explain modular arithmetic as I went along. Let me know if this made sense.

Last edited:
Yeah, I made some sense of it. I don't know much about modular arithmetic, but I'm gonna start googling it! lol, thanks for the response!

Main idea is to look at everything mod 9. Meaning, look at everything with respect to the remainder when divided by 9.

52 has remainder 7. And that fact stays the same no matter how many piles you divide the 52 into. So there are 3 piles, A, B, and D. So A+B+D = 52 (mod 9) [here I'm using '=' instead of the three-bar symbol to avoid using markup.]

Therefore A+B = 52 - D (mod 9).

The right side does not change if you replace 52 with 16 since they have the same remainder. So

A + B = 16 - D (mod 9)

Now that's all well and good, but there is one more trick: If you add the digits of any number, you get the same result as if you took the remainder (mod 9) of the original number.

So we have the relationship A + B = 16 - D (mod 9), and then we just add the digits on each side. The dealer adds the digits of the number of his own cards; subtracts from 16; adds digits again if needed, and that's the same number you get when you add the digits of the number of cards of A and B.

That's the same thing I said before but it's shorter!

Blaise Pascal once sent someone a long letter, explaining, "The present letter is a very long one, simply because I had no leisure to make it shorter."

very interesting, thanks!

I've got another trick that I figured out a formula for, through trial and error. Interested?

Here's the set up, 52 cards.
I pick a random card, say its a 7, then i place cards under it, one for 8,9,10,11,12, and 13. that makes one pile.

then say the next card is a 10. I do the same for it, putting the 10 on top and counting one card for 11, one for 12 and one for 13. - it has 4 cards total in the pile.

and the next card i pull is a 4. so I put 9 cards under it - 10 total cards in the pile.

I do this until I run out of cards or don't have enough for a complete pile.

then I have someone choose 3 piles, and I pick up the rest.

Of the 3 piles, the top card on two of them is flipped over so it faces up. say these are a 4 and a 10.

I take 4+10 = 14, and 14+10 is 24. So I count 24 cards from my hand. The number of remaining cards in my hand is the value of the third card, which is 7.

Some guy at a bar taught me this trick, and I could do it over and over and never knew why it worked. I attempted to find an explanation, and I worked out a formula that sort of models it. This was done only with algebra and guesses lol

R is the number of cards in my hand, and $N_{x}$ is the number of cards in pile x

52= R + $N_{A} + N_{B} + N_{C}$

$N_{A}$ = 14-[A] where [A] is the value shown (ex 10 card, 14-=4 cards in pile)

52 = R + 14-[A] + 14- + 14-[C]

52-3*14 = 10 = R-[A]--[C]

[C]=R - [A] - - 10

[C]=R-([A] + + 10)

which means [C] is the number of cards remaining in my hand after doing the subtraction.

Is there an explanation for this trick through set theory or modular arithmetic? My explanation of why it works is just that it's algebra. Lol.