-3

A friend of mine told me about this problem.

Given a indexed sequence of 13 cards from Ace to King, there is a machine which shuffles them and gives a certain (indexed) output sequence. Now inserting this output again in the machine, it gives another indexed sequence in the order:

Jack, 9, Queen, Ace, King, 3, 5, 2, 6, 4, 7, 10, 8

From the given information, we have to determine what is the algorithm of the machine?

I was thinking of a mapping f which represents the algorithm of machine such that:

$f(Ace) = x_1; f(x_1) = \text{Jack}$

But I don't know what to do of it even? Thank your reading.

  • 3
    You probably want something like https://math.stackexchange.com/questions/266569/how-to-find-the-square-root-of-a-permutation – HighDiceRoller Mar 04 '24 at 19:33

1 Answers1

2

First choose an encoding of the cards as integers $1, 2, \dots, 13$. The usual one is to assign $1$ to Ace, use the value of the cards for $2$ through $10$, then assign $11$ to Jack, $12$ to Queen, and $13$ to King. Now we have the a permutation $\sigma \in S_{13}$ such that $$ \tau = \sigma^2 = \begin{pmatrix} 11 & 9 & 12 & 1 & 13 & 3 & 5 & 2 & 6 & 4 & 7 & 10 & 8 \\ 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 \end{pmatrix}. $$ This is two-line notation, denoting the fact that $\tau(11) = 1$, or that the Jack is moved from position $11$ to position $1$, etc. The pairs are sorted by the bottom row, which indicates where in the deck each card lands. It's typical to represent the permutation by rearrange the pairs, sorting by the top row, yielding the equivalent $$ \tau = \begin{pmatrix} 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 \\ 4 & 8 & 6 & 10 & 7 & 9 & 11 & 13 & 2 & 12 & 1 & 3 & 5 \end{pmatrix}, $$ where each card rank is in order, and the place in the deck where it lands is indicated below, i.e. since $\tau(1) = 4$, this shows that the Ace is shuffled to position $4$.

However, neither of these two equivalent representations are terribly useful. A better way to look at $\tau$ is in cycle notation. Begin with any number, say $1$, and apply the permutation until we return to the starting number. Then, repeat this for any remaining numbers, until every number is in exactly one cycle. In this case, there's just one cycle $$ 1 \mapsto 4 \mapsto 10 \mapsto 12 \mapsto 3 \mapsto 6 \mapsto 9 \mapsto 2 \mapsto 8 \mapsto 13 \mapsto 5 \mapsto 7 \mapsto 11 \mapsto 1, $$ so the permutation $\tau$ is the $13$-cycle $$ \tau = \begin{pmatrix} 1 & 4 & 10 & 12 & 3 & 6 & 9 & 2 & 8 & 13 & 5 & 7 & 11 \end{pmatrix}, $$ And since $13$ is odd, we are guaranteed to be able to find a $\sigma$ such that $\sigma^2 = \tau$.

How? In cycle notation, when we apply the permutation to a number, we land at the next number, so applying the permutation twice in succession, we jump ahead two places. This suggests that if we want $\sigma^2 = \tau$, then we should begin by placing the first half of the cycle for $\tau$ in $\sigma$, but spaced $2$ apart, i.e. $$ \sigma = \begin{pmatrix} 1 & \square & 4 & \square & 10 & \square & 12 & \square & 3 & \square & 6 & \square & 9 \end{pmatrix}, $$ where the $\square$ spots are yet to be filled. But jumping ahead $2$ spots (cyclically) lands in the first unfilled spot$^\dagger$, so we continue until the entire cycle is completed: $$ \sigma = \begin{pmatrix} 1 & 2 & 4 & 8 & 10 & 13 & 12 & 5 & 3 & 7 & 6 & 11 & 9 \end{pmatrix}. $$ You can easily check by jumping $2$ spaces at a time that $\sigma^2 = \tau$.

Back in two line notation, $$ \tau = \sigma^2 = \begin{pmatrix} 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 \\ 2 & 4 & 7 & 8 & 3 & 11 & 6 & 10 & 1 & 13 & 9 & 5 & 12 \end{pmatrix}, $$ or sorting by the bottom row, i.e. where each card lands in the deck, $$ \tau = \sigma^2 = \begin{pmatrix} 9 & 1 & 5 & 2 & 12 & 7 & 3 & 4 & 11 & 8 & 6 & 13 & 10 \\ 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 \\ \end{pmatrix}, $$

This means that the initial shuffle was $$ 9,\, \text{A},\, 5,\, 2,\, \text{Q},\, 7,\, 3,\, 4,\, \text{J},\, 8,\, 6,\, \text{K},\, 10. $$


$^\dagger$ This is where the fact that $13$ is odd becomes relevant. If the cycle is of even length, then another method must be employed.

Sammy Black
  • 25,273