-1

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 ?

Utkarsh Kumar
  • 567
  • 1
  • 5
  • 17
  • Google suggests [Lehmer code](http://en.wikipedia.org/wiki/Lehmer_code) for encoding permutations as numbers. – Kevin Apr 17 '14 at 19:05
  • The reverse, which may also help - [Find the index of a given permutation in the sorted list of the permutations of a given string](http://stackoverflow.com/q/5131497) – Bernhard Barker Apr 17 '14 at 19:11

1 Answers1

1

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

wvdz
  • 16,251
  • 4
  • 53
  • 90