e
TokenTree
s but in the end I just copied enum from lexer the only different is that it has #[repr(C)]
:\def permutation_by_index (items, idx):
if idx >= math.factorial(len(items)) or idx < 0:
raise Exception("uh-oh")
remaining = items.copy()
remaining_index = idx
result = []
for i in range(len(items)):
divisor = int(math.factorial(len(items) - i - 1))
result.append(remaining.pop(remaining_index // divisor))
remaining_index %= divisor
return result
(edited)