Created
January 8, 2016 15:43
-
-
Save ChristianGaertner/b111df62775ec1517d5f to your computer and use it in GitHub Desktop.
Grouptable Generator of Square
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The elements (corners) of the squae | |
elements = ["a", "b", "c", "d"] | |
ops = { | |
'i': {"a": "a", "b": "b", "c": "c", "d": "d"}, #identity | |
'r': {"a": "b", "b": "c", "c": "d", "d": "a"}, # rot 90 | |
's': {"a": "c", "b": "d", "c": "a", "d": "b"}, # rot 180 | |
't': {"a": "d", "b": "a", "c": "b", "d": "c"}, # rot 270 | |
'x': {"a": "d", "b": "c", "c": "b", "d": "a"}, # mirror x | |
'y': {"a": "b", "b": "a", "c": "d", "d": "c"}, # mirror y | |
'z': {"a": "c", "b": "b", "c": "a", "d": "d"}, # mirror z | |
'w': {"a": "a", "b": "d", "c": "c", "d": "b"} # mirror w | |
} | |
# resolve single argument | |
def resolve(input, op1, op2): | |
return op2.get(op1.get(input)) | |
# resolve every corner of square | |
def make(op1, op2): | |
retDict = {} | |
for e in elements: | |
retDict[e] = op2.get(op1.get(e)) | |
return retDict | |
# find corresponding operation | |
def resolve(op1, op2): | |
result = make(op1, op2) | |
for op, comb in ops.items(): | |
if result == comb: | |
return op | |
# print a nice table | |
def printAll(): | |
print(end=" |") | |
[print(name, end=" ") for name in sorted(ops)] | |
print() | |
[print("---", end="") for name in sorted(ops)] | |
print() | |
for name0 in sorted(ops): | |
print(name0, end="|") | |
for name1 in sorted(ops): | |
print(resolve(ops.get(name0), ops.get(name1)), end=" ") | |
print() | |
printAll() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment