Doing Magic Using Permutations
Table of Contents
I recently started reading an interesting little book about doing “magic” using tricks that are based primarily on mathematics, instead of deception and dexterity. Inspired by some of the ideas, I have been playing around with a deck of cards and came up with a little trick of my own. I can imagine that this kind of trick could be already old news and described elsewhere, but as I do not have any sources for it, so I decided to write it down.
The Magic Act
The magician has a deck of 16 cards. They may be briefly shown to the observer.
The following sequence of steps can be done arbitrarily many times:
- The cards are distributed clockwise into four stacks of four cards.
- The observer picks one of the four stacks.
- The stacks are collected, in counter-clockwise order, ensuring that the selected stack is now on top, the next is below it, etc.
After doing this a few times (either a fixed number, like 3, or until the observer is satisfied), the magician starts putting cards from the deck to the side, one by one, and the observer may stop the magician at any time.
Then the magic happens: the magician predicts the suit of the next card, and flips it over – confirming that the prediction is right. The observer is (hopefully) a bit impressed.
How Does It Work?
Preparation
The key ingredient of the trick is that the deck is (of course) prepared, and the kind of “mixing” that is done lets us infer the suits of any card at all times. In the following you will see how this is done.
First we need to identify card suits with numbers, I use ♦$\to$1, ♥$\to$2, ♠$\to$3 and ♣$\to$4. Next, pick a subset of 16 cards, 4 of each suit, from any standard deck of playing cards. Arrange them in such a way that the order of suits is as follows:
top $\rightarrow$ 4,1,2,3,3,4,1,2,2,3,4,1,1,2,3,4 $\leftarrow$ bottom
Note the special structure of that order: $(\mathbf{4},1,2,3),(\mathbf{3},4,1,2),(\mathbf{2},3,4,1),(\mathbf{1},2,3,4)$
The order is highly symmetric – the last number of each group of four consecutive cards is the first number of the next group, the first numbers of the groups (in bold) cyclically count backwards, while each group is a shifted sequence counting upwards, modulo 4. Furthermore, one can consider the deck to be cyclic: we can put 4 cards from the top to the bottom (or vice versa) without breaking any property.
The “Mixing” Step
Note that the suit of the top and bottom card of the deck are always the same, and that the last card of every group of 4 cards will be the top card of the respective 4 stacks. So starting from the initial configuration, after distributing the cards clockwise, the four stacks will look as follows:
- $S_1$: 1,2,3,4
- $S_2$: 2,3,4,1
- $S_3$: 3,4,1,2
- $S_4$: 4,1,2,3
Due to the preparation in the beginning, we knew that $S_4$ must have 4 on top (or alternatively, you can remember that $S_1$ has $1 = (4+1) \mod 4$ on top).
In general, the suit of the top card of the stack $S_i$ the observer picked in the last round of “mixing”, which then was the top card of the whole deck, ends up being the top card of the stack $S_4$ of the current round.
As the suits of the top cards also follow the cyclic modulo 4 counting pattern, we therefore know the top cards of the other stacks (and in fact, of all cards – which we use in the final part of the trick).
Now when the observer picks a stack (that next will be on top of the deck), you only need to remember which suit $n$ the top card of that stack has, and in the next round, the suits of the top cards of the stacks will be:
- $S_1$: $(n+1) \mod 4$
- $S_2$: $(n+2) \mod 4$
- $S_3$: $(n+3) \mod 4$
- $S_4$: $n$
Hence, the only information you have to be aware of is a single number between 1 and 4 from which you can “see” the suits of the top cards all the time.
Just to make sure that it is clear how to correctly pick up the stacks – if the observer now picks stack $S_2$, which has suit 2 on top, then we pick up the stacks counter-clockwise, resulting in a new deck with the following order:
top $\rightarrow$ 2,3,4,1,1,2,3,4,4,1,2,3,3,4,1,2 $\leftarrow$ bottom
So in the next round, we have the following stacks in front of us:
- $S_1$: 3,4,1,2
- $S_2$: 4,1,2,3
- $S_3$: 1,2,3,4
- $S_4$: 2,3,4,1
The Grand Finale
As we are at all times fully aware of the order of suits in the deck and the resulting new stacks, when we finally start putting the cards to the side one by one, we can simply mentally count up (modulo 4) to keep track of the suits. It is just important to remember that after every 4 cards, one number is duplicated. Then just convert the number of the top card of the remaining deck (the one to be predicted) back into a suit.
Discussion
A major weakness of this trick is that the order is pretty fragile. Any kind of (pseudo-)shuffle would need to be very controlled and ensure that only groups of four cards can wander from the top to the bottom of the deck, or vice versa, and we still know which group/suit is currently on top.
Coming up with ideas how to convince the observer of the “randomness” of the cards here would make it much more interesting, but I don’t have a good idea how to pull it off or make clever use of a Gilbreath-style shuffle.
Variations
Intermediate: Using a different deck size
In theory, the trick works with any quadratic number of cards, so instead of $4\times 4$ it could be any $n \times n$. Practically the versions with $n\in\{3,4,5,6\}$ seem to be the range of interesting parameters, but only the version with 16 cards and 4 different values (i.e., the suits) seems to match naturally with standard playing cards.
Adapting the combinatorics to e.g. 25 cards and using a property with 5 distinct values is straight-forward (I leave it as an exercise for the reader), but maybe needs some creative custom card design.
Advanced: Predicting the exact card
What would be more spectacular than just predicting the suit? Of course – predicting the exact card. However, this comes at a huge cost of practicality. I came up with a version of this trick where you, in theory, can know the exact cards, but at the cost of making the mental arithmetics too impractical (at least for me), and requiring the deck to be even more symmetric. So if you would really consider pulling it off, in this version I suggest not revealing the deck in the beginning, even briefly.
But mathematically, it can be done as follows. When selecting a subset of 16 cards, now also make sure to have 4 cards with 4 distinct values. For example, we can use only the 7s, 8s, 9s, and 10s of a deck. Naturally, we will identify them with numbers from 1 to 4 too, e.g. $7 \to 1, 8\to 2, 9\to 3, 10\to 4$.
In the original version, we ignored the values completely. Now, we will see all the permutation action going on in the deck. We will write a card as $\binom{n}{m}$, where $n$ is the number of the suit, and $m$ is the number corresponding to the value/type of the card.
The important observation is that while the suits behave as before, the card values permutate is a slightly more complicated way – the stacks will alternate between a state where each stack contains
- the same card (of different suits), ascending in clockwise order of the stack
- all four distinct cards (of different suits), in the same order as the other stacks
The start configuration now is:
$$ \footnotesize \binom{4}{1},\binom{1}{2},\binom{2}{3},\binom{3}{4}, \binom{3}{1},\binom{4}{2},\binom{1}{3},\binom{2}{4}, \binom{2}{1},\binom{3}{2},\binom{4}{3},\binom{1}{4}, \binom{1}{1},\binom{2}{2},\binom{3}{3},\binom{4}{4} $$
The first time we create the four stacks (from our start deck), we will get:
- $S_1 = \binom{1}{1},\binom{2}{1},\binom{3}{1},\binom{4}{1}$
- $S_2 = \binom{2}{2},\binom{3}{2},\binom{4}{2},\binom{1}{2}$
- $S_3 = \binom{3}{3},\binom{4}{3},\binom{1}{3},\binom{2}{3}$
- $S_4 = \binom{4}{4},\binom{1}{4},\binom{2}{4},\binom{3}{4}$
Note that the stacks are in the equal phase (each stack has all cards of the same value). Now, assuming that (as in the previous example), the observer picks stack $2$, next time the stacks will be:
- $S_1 = \binom{3}{3},\binom{4}{4},\binom{1}{1},\binom{2}{2}$
- $S_2 = \binom{4}{3},\binom{1}{4},\binom{2}{1},\binom{3}{2}$
- $S_3 = \binom{1}{3},\binom{2}{4},\binom{3}{1},\binom{4}{2}$
- $S_4 = \binom{2}{3},\binom{3}{4},\binom{4}{1},\binom{1}{2}$
So the stacks now are in the ascending phase. If we do it again, and pick e.g. $S_3$ (which has suit 1 on top), we will get:
- $S_1 = \binom{2}{3},\binom{3}{3},\binom{4}{3},\binom{1}{3}$
- $S_2 = \binom{3}{4},\binom{4}{4},\binom{1}{4},\binom{2}{4}$
- $S_3 = \binom{4}{1},\binom{1}{1},\binom{2}{1},\binom{3}{1}$
- $S_4 = \binom{1}{2},\binom{2}{2},\binom{3}{2},\binom{4}{2}$
So when going from ascending to equal phase, the “order” of the card values does not change – only the “phase” does, but the order does also change when going from equal to ascending.
To succinctly write down the rule how the deck changes, we need a short notation for the current state of the deck (which is also the information we have to remember). Let us write $(n, m, p)$ with $n, m \in\{1,2,3,4\}, p\in\{=,\downarrow\}$, where $n$ is the suit of the first stack, $m$ is the value of the first stack and $p$ is the equal or ascending phase.
Then the start deck $D_1$ corresponds to the state $(1,1,=)$, the next deck $D_2$ (after choosing the stack with $2$ on top) is $(3,3,\downarrow)$, and the next deck $D_3$ (after choosing the stack with $1$ on top) is $(2,3,=)$.
With this, I can present the rule how the state changes to the next, depending on the suit $i$ of the top card of the stack the observer chooses:
- $(n, m, \downarrow) \overset{i}{\rightarrow} ((i+1)\mod 4, m, =)$
- $(n, m, =) \overset{i}{\rightarrow} ((i+1)\mod 4,(m + i+1 - n)\mod 4, \downarrow)$
So in this theoretical version of the trick, you can reconstruct the complete deck from your state information, and thus can “predict” any card the observer can choose in the end.
If you think you can memorize this and actually do modular arithmetic on two numbers in a live setting, using two different rules that depend on an additional bit of information – then you have my admiration and I wish you the best of luck!