Question

There are 4 items
-I1
-I2
-I3
-I4

The possible order of these items is 4! = 24. In order to save space, I need to use only 5 bits to represent each of the unique 24 permutations.

What is the most efficient way to reverse engineer a specific priority order in the list if we just have a number as input ? In general, how do we do this for n items ? Is there any algorithm in place ?

Was it helpful?

Solution

The Lehmer code can be used for this. This looks like a pretty decent guide on how to do that: http://www.2ality.com/2013/03/permutations.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top