Advertisement
here2share

# index_permu.py

Apr 6th, 2022
1,109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.36 KB | None | 0 0
  1. # index_permu.py
  2.  
  3. def index_permu(alist, index):
  4.     alist = alist[:]
  5.     for i in range(len(alist)-1):
  6.         index, j = divmod(index, len(alist)-i)
  7.         alist[i], alist[i+j] = alist[i+j], alist[i]
  8.     return alist
  9.    
  10. i = 0
  11. ttt = []
  12. while 1:
  13.     t = index_permu([9,8,7,2,3,1], i)
  14.     if t not in ttt:
  15.         ttt += [t]
  16.         print (t)
  17.         i += 1
  18.     else:
  19.         break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement