1
0
mirror of https://github.com/osmarks/random-stuff synced 2024-12-26 18:10:34 +00:00
random-stuff/cycdec.py
2023-06-19 14:09:54 +01:00

19 lines
332 B
Python

perm = [
[1, 2, 3, 4, 5, 6, 7, 8],
[5, 7, 8, 2, 3, 6, 4, 1]
]
perm = dict(zip(*perm))
vals = set(perm)
print(perm)
cycs = []
while vals:
nxt = vals.pop()
seen = []
while nxt not in seen:
lnxt = nxt
nxt = perm[nxt]
seen.append(lnxt)
cycs.append(seen)
vals -= set(seen)
print(cycs)