Project Euler Lab - Problem 622

#622 - Riffle Shuffles

● AdvancedOfficial difficulty: 36%RandomnessTier C - reduced scale in browser; full scale in notebookNot viewed
↖ Euler Lab

A riffle shuffle is executed as follows: a deck of cards is split into two equal halves, with the top half taken in the left hand and the bottom half taken in the right hand. Next, the cards are interleaved exactly, with the top card in the right half inserted just after the top card in the left half, the 2nd card in the right half just after the 2nd card in the left half, etc. (Note that this process preserves the location of the top and bottom card of the deck)

Let \(s(n)\) be the minimum number of consecutive riffle shuffles needed to restore a deck of size \(n\) to its original configuration, where \(n\) is a positive even number.

Amazingly, a standard deck of \(52\) cards will first return to its original configuration after only \(8\) perfect shuffles, so \(s(52) = 8\). It can be verified that a deck of \(86\) cards will also return to its original configuration after exactly \(8\) shuffles, and the sum of all values of \(n\) that satisfy \(s(n) = 8\) is \(412\).

Find the sum of all values of n that satisfy \(s(n) = 60\).

This problem is taken from Project Euler, Problem 622.
Problem text © Project Euler, licensed under CC BY-NC-SA 4.0. Original: projecteuler.net/problem=622. Published Sunday, 11th March 2018, 07:00 am. Solved by 2,017 members at time of mirroring.

Why this is useful

Probability Statistics. Expectation and state-based probability reasoning underpin pricing, risk, and statistical inference (Phases 7, 11, 13).

We classify relevance honestly - not every Euler problem is a trading application.

Learning mode

Pick how much scaffolding you want. Your choice is remembered per problem.

Scratchpad

Mathematical notes, formulas, pseudocode, hypotheses, complexity notes. Saved automatically with your progress.

Python workbench

Tier C - reduced scale in browser; full scale in notebook
Browser runs a reduced, clearly-labelled educational scale; the original scale is provided in a local notebook.

Real Python (Pyodide) in a sandboxed Web Worker - no network, no filesystem, no DOM access. Ctrl/Cmd+Enter runs. Escape leaves the editor. Stop terminates the worker.

Python runtime not loaded (it boots on first run - a one-time local load).

Check your answer

Answers are checked against a salted hash held in a separate file - not printed in this page. This prevents accidental spoilers; it is not cryptographic protection (see the build notes).

Progressive hints

Confidence

Low confidence schedules this problem for spaced review, even if you solved it.

Reference solution

Spoiler
The complete original explanation (interpretation, naive approach, insight, proof, complexity, Python implementation, tests, common mistakes, alternatives) is hidden and lazy-loaded. Reveal it only after a meaningful attempt - the struggle is where the learning happens.