Useless CP Information #10: Shuffling Poker Chips

Revision en1, by greateric, 2026-08-15 18:28:35

Backstory: "Problem statement v2" was a problem I tried to propose for our round. Unfortunately, a really similar version ("Problem statement v1") has been used before. But then we had the question of if these two problem statements were actually the same or different. Are the answers to both problems always going to be the same, or is there an example out there where they differ?

Problem statement v1

This is a problem you might have seen before.

Eric has $$$n$$$ (where $$$n$$$ is even) poker chips. They are currently in a stack, the bottom one is numbered $$$1$$$, the second-bottom one is numbered $$$2$$$, ..., the top one is numbered $$$n$$$. Eric will shuffle the poker chips by interleaving the bottom half and the top half together. Formally, this permutes the stack from

$$$1, 2, ..., n$$$

to

$$$1, \frac{n}{2}+1, 2, \frac{n}{2}+2, 3, \frac{n}{2}+3, ..., \frac{n}{2}, n.$$$

How many shuffles must he perform to revert to the starting position? (Find the minimum number)

Constraints: $$$n \le 200{,}000$$$.

Solution v1

Spoiler

Problem statement v2

Eric has $$$n$$$ (where $$$n$$$ is even) poker chips once again. The shuffle operation is the same: $$$1, 2, ..., n \rightarrow 1, \frac{n}{2}+1, 2, \frac{n}{2}+2, 3, \frac{n}{2}+3, ..., \frac{n}{2}, n$$$.

But, this time, the bottom $$$m$$$ poker chips are white, and the top $$$n-m$$$ poker chips are green. We are interested in the minimum number of shuffles until all $$$m$$$ white chips are on the bottom and all $$$n-m$$$ green chips are on top again. The stack does not have to be sorted; for example, if $$$n = 6$$$ and the white chips are $$$1, 2, 3$$$ and the green chips are $$$4, 5, 6$$$, then $$$[1, 3, 2, 5, 4, 6]$$$ would count as good.

The problem: Prove that the answer to this problem is always the same as previous (aka if white and green are separated, then the stack must be sorted), or find an example where it is faster to get a white/green stack than a sorted stack.

There is now no constraint on $$$n$$$ other than it has to be even. We avoid the trivial case of $$$m = 1$$$ or $$$n - m = 1$$$, since if there is only 1 chip of either color, then it forever stays on the top/bottom so you get a white/green stack after every operation.

Solution v2

Thanks to Puddles_Penguin, daniel.glabai, and ClaudeFable5 for working through this.

Spoiler
Tags math, permutations

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English greateric 2026-08-15 18:28:35 6286 Initial revision (published)