Problem context and objectives
Mission briefing
Puzzle systems engineer · A game mechanic is behaving incorrectly
Let only the first unused duplicate branch: The Unique Wheel.
Brute force may pass the demo but fail when the world fills with players.
How you win
- 1Recognize when Unique permutations matches the clues
- 2Keep this true after every move: each depth opens at most one branch for each distinct remaining value
- 3Reach the result within O(number of unique permutations times n)
Rules and pressure
- Target cost: O(number of unique permutations times n)
- State rule: each depth opens at most one branch for each distinct remaining value
Lesson 1 of 3
Live algorithm trace
Unique permutations
Complete execution1 of 6
1
choice
1
2
0
1
2
At the root, the first 1 may branch before its duplicate.
1
sort values2
if path complete: record3
scan candidate indices4
skip used indices5
skip duplicate when previous equal index is unused6
choose, recurse, and undosorted = [1,1,2]path = []
Truth to preserve / Cost target
Truth to preserve
each depth opens at most one branch for each distinct remaining value
Cost target
O(number of unique permutations times n)
Sorting groups duplicates. At one position, skip an equal value when its previous copy is still unused, because that previous copy would create the same branch first.
Your call · What should guide every step of this algorithm?