01How it works
Check whether the array is sorted. If not, shuffle it uniformly at random and check again. Repeat forever — or, in this implementation, until a sanity cap trips and the player gives up.
Shuffle until sorted. Joke algorithm — capped to stay polite.
Check whether the array is sorted. If not, shuffle it uniformly at random and check again. Repeat forever — or, in this implementation, until a sanity cap trips and the player gives up.
Jokes, teaching what "expected runtime" means, and illustrating the gulf between best-case and average-case analysis. Also a surprisingly decent stress test for random-number generators.
Every other moment of your life. Expected time is O((n+1)!) — at n = 30 the expected runtime already outlives the heat death of the universe.