Skip to main content
100%

Find Circles in Permutations of Unique Numbers (for 100 prisoners problem)

✓ Published0🌍 Public
RRestuta
Last edited Dec 26, 2016
Created on Dec 26, 2016

This example visualizes the decomposition of a random permutation of numbers 1–100 into cycles, as used in the 100 prisoners problem. It shuffles an array with a custom Fisher–Yates algorithm, then recursively traces each number to its mapped successor to identify circular chains. The code outputs each cycle as a separate array via `console.log`, with no graphical rendering library; all logic is plain JavaScript. The visualization highlights how permutations break into closed loops, and it verifies that the sum of all cycle lengths equals the original array length.

AI-generated description

Similar vizzes