Advertisement
here2share

# idx_permu.py

Mar 12th, 2025
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.56 KB | None | 0 0
  1. # idx_permu.py
  2.  
  3. import math
  4.  
  5. def idx_permu(idx, length=8):
  6.     elements = list(range(length))
  7.     result = []
  8.    
  9.     for i in range(length - 1, -1, -1):
  10.         facto = math.factorial(i)
  11.         pos = idx // facto
  12.         result.append(elements.pop(pos))
  13.         idx %= facto
  14.    
  15.     return result
  16.  
  17. length = 6
  18. facto = math.factorial(length)
  19. i = step = int(facto * 0.7)
  20.  
  21. stop = []
  22. j = 1
  23. while 1:
  24.     result = idx_permu(i, length)
  25.     if result in stop:
  26.         break
  27.     print(result, j)
  28.     stop += [result[:]]
  29.     i = (i + step) % facto
  30.     j += 1
  31. print(facto)
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement