cards, labelled 0, 1, …, cards - 1 from top to bottom. One perfect shuffle works like this: split the deck exactly in half, then interleave the halves card by card: first card of the top half, first card of the bottom half, second card of the top half, second of the bottom half, and so on.
For example, 0 1 2 3 becomes 0 2 1 3.
Return how many shuffles (at least one) it takes until the deck is back in its original order for the first time.cards=6 → 4
0 1 2 3 4 5 → 0 3 1 4 2 5 → 0 4 3 2 1 5 → 0 2 4 1 3 5 → 0 1 2 3 4 5: four shuffles.
cards=2 → 1
With two cards, the deck is 0 1 again right after the first shuffle.
cards=8 → 3
A deck of 8 cards comes back to its starting order after 3 shuffles.
cards ≤ 1000cards is evencards=6
4
Run checks the first 3 tests in your browser. Submit checks all 40 tests on the server, hidden ones included.