# idx_permu.py import math def idx_permu(idx, length=8): elements = list(range(length)) result = [] for i in range(length - 1, -1, -1): facto = math.factorial(i) pos = idx // facto result.append(elements.pop(pos)) idx %= facto return result length = 6 facto = math.factorial(length) i = step = int(facto * 0.7) stop = [] j = 1 while 1: result = idx_permu(i, length) if result in stop: break print(result, j) stop += [result[:]] i = (i + step) % facto j += 1 print(facto)