made tuple_reorientation to a general utility file

This commit is contained in:
=
2024-02-06 15:45:07 +01:00
parent eafb8865ae
commit a346503697

27
python/tuple_tools.py Normal file
View File

@@ -0,0 +1,27 @@
def reorient_tuple(t, n):
t, _ = _invert(*_flip(*_rotate(t, n)))
return t
def _rotate(t, n) -> tuple[tuple, int]:
m = n%3
return t[m:] + t[:m], n//3
def _flip(t, n) -> tuple[tuple, int]:
match n%4:
case 1:
return (-t[0], -t[1], t[2]), n//4
case 2:
return (-t[0], t[1], -t[2]), n//4
case 3:
return (t[0], -t[1], -t[2]), n//4
case _:
return t, n//4
def _invert(t, n) -> tuple[tuple, int]:
match n%2:
case 1:
return (-t[0], -t[1], -t[2])[::-1], n//2
case _:
return t, n//2