Write a program or function that takes in a 4×4 text grid consisting of exactly 4 A
's, 4 B
's, 4 C
's, and 4 D
's, such as:
ACDC
BBCA
BADD
ABCD
The ABCD
's may be in any arrangement but there will always be 4 of each. You can assume the input is valid. If desired you can also assume it has a trailing newline and/or that it comes as one line in reading order, e.g. ACDCBBCABADDABCD
. You may also replace the characters ABCD
with 0123
or 1234
respectively, if desired (but that's all).
Output a truthy value if the text grid has any form of reflective or rotational symmetry. Specifically:
If there is a central horizontal line of symmetry. e.g.
BACD BACD BACD \___ bottom mirrors top BACD /
If there is a central vertical line of symmetry. e.g.
BCCB DAAD CAAC BDDB \/___ right mirrors left
If there is a diagonal line of symmetry (in either direction). e.g.
___ diagonally mirrored / ABDC BACD DCAB CDBA \___ diagonally mirrored
If there is 90° rotational symmetry. e.g.
BDAB ACCD same if rotated 90 degrees (or 180 or 270) DCCA BADB
If there is 180° rotational symmetry. e.g.
DBCA BDCA same if rotated 180 degrees ACDB ACBD
(Note that translational symmetry doesn't come into play here.)
Output a falsy value if the grid doesn't have one of the symmetries mentioned above. e.g. the very first example grid.
The shortest code in bytes wins.