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

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

  •  05-07-2023
  •  | 
  •  

문제

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 ?

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top