Advertisement
here2share

# idx_permu_plus.py

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