Advertisement
Guest User

Untitled

a guest
Nov 21st, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.32 KB | None | 0 0
  1. k-th permutation of n elements [a b c d ... ]
  2.  
  3. idx1 = int(k/(n-1)!)
  4. k = k % (n-1)!
  5.  
  6. idx2 = int(k/(n-2)!)
  7. k = k % (n-1)!
  8.  
  9. idx3 = int(k/(n-3)!)
  10. k = k % (n-1)!
  11.  
  12. ...
  13.  
  14. idxn = ...
  15.  
  16. Then extract the element idx1 from the array of elements (it results in a new array)
  17. From the new array pick the idx2 element
  18. And so on
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement