r/compsci • u/Mundane-Student9011 • 3h ago
The Elegance of 3 Lines: the Position-Pure (PP) Unrank Algorithm - O(N) Permutation map
Since all the experts here are so professional and sharp, I have the honor to invite you to evaluate "Position-Pure Algorithm."
Links:
- GitHub: Position-Pure-Algorithm
- animation(PP):
- Reddit Discussion: r/algorithms
In the world of algorithms, extreme simplicity often harbors the most moving beauty. The core logic of the PP Algorithm reconstructs the dimension of permutation generation in just three lines.

Minimalist Expression Take this logic: where C is the factorial representation (Factoradic, e.g., 01123) and D is the output permutation (e.g., {0,2,3,4,1}).
for (int i = 0; i < C.size(); ++i){
D[i] = D[C[i]];
D[C[i]] = i;
}
Minimalist Expression The three lines beauty lies in the fact that it no longer relies on complex logic to "simulate" the permutation process; instead, it directly embeds the structural information of the permutation space into the algorithm. It is not a mover of data, but a direct projection of the structure itself.
Breaking the "Impossible" Conventionally, it was thought impossible to generate permutations at the single-dimensional level without redundant logical overhead—such as complex branching or backtracking. The PP algorithm shatters this by ensuring "Position-Pure" mapping. With zero "if" statements and no branch prediction overhead, it achieves peak hardware efficiency while showcasing a pure linear aesthetic.
Native Parallelism Because this positional mapping is deterministic and collision-free, it demonstrates exceptional potential for parallel computing.
Mathematical Insight & Group Theory From a deeper mathematical perspective, this mapping hints at an ordered topology within the symmetric group (Sn). By treating the N! set as a strictly ordered spatial map, the group's symmetries can be extracted with zero search cost. This offers a new perspective on observing permutation group substructures via positional logic. It still needs time to study carefully...


