Printing a unique order of 4 items from a unique input between 0-23 [duplicate]

StackOverflow https://stackoverflow.com/questions/23141370

  •  05-07-2023
  •  | 
  •  

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 ?

Était-ce utile?

La 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

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top