The card sorting problem or card cyclicity problem is a combinatorial problem that can be solved using group theory, specifically the notion of permutation cycles and the concept of least common multiple (LCM).
Given a deck of 52 shuffled cards, suppose we want to sort the cards in ascending order, which for simplicity, can be represented by the numbers 1 to 52. This means that we want every card to be in its original (sorted) position in the deck. Let us formalize this with being a permutation (a bijection) of the deck, such that:
Οβ:β{1,β2,ββ¦,β52}βββ{1,β2,ββ¦,β52}
For a given shuffle represented by the permutation Ο, we want to find the minimum number n such that applying the permutation n times returns the deck to the original sorted order. That is, we want to find the smallest integer n such that Οn(i)β=βi for all 1ββ€βiββ€β52.
Now, letβs consider the decomposition of the given permutation Ο into its disjoint cycles. A permutation cycle of length k is a sequence of integers c1,βc2,β...,βck such that applying the permutation k times brings each element back to its original position:
Οk(ci)β=βciβ
+β
1;
for iβ=β1,β2,ββ¦,βkβ ββ 1 and
Οk(ck)β=βc1.
Since the cycles are disjoint, each card belongs to exactly one cycle. Letβs say the given shuffle Ο can be decomposed into disjoint cycles with lengths: c1,βc2,β...,βcm.
To find the minimum number of times we need to sort the cards to return them to their original sorted order, we need to apply the permutation the least common multiple of cycle lengths times, i.e.,
nβ=βlcmβ(c1,βc2,β...,βcm).
This is because the least common multiple ensures that all cards in all cycles cycle back to their original positions simultaneously.
Therefore, the minimum number of times you need to sort the deck is the least common multiple of the lengths of the disjoint cycles of the given permutation.
As an example, letβs take a simple deck of 4 cards, with the given shuffle Οβ=β(14)(23), which is already expressed in its cycle notation. The lengths of the cycles here are 2 and 2, i.e., (c1,βc2)β=β(2,β2). The least common multiple of these lengths is:
lcmβ(2,β2)β=β2.
Thus, in this example, we need to sort the cards at least 2 times to return them to their original sorted order.