23
1
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.
Can we take a list of four strings as input? – Martin Ender – 2016-08-18T08:11:14.827
@MartinEnder Yes, alright. – Calvin's Hobbies – 2016-08-18T08:13:59.060
4I just read that and thought "nope" lol – Shaun Wild – 2016-08-18T08:22:56.467
Had you thought to tile the square then you could have taken translational symmetry into account too. – Neil – 2016-08-18T10:10:55.280
May I take input as an enclosed array? I.e. a single element, whose value is a 4×4 table? – Adám – 2016-08-18T12:04:50.150
1@Adám No. No more input formats. I feel I shouldn't really have allowed Martin's. – Calvin's Hobbies – 2016-08-18T12:31:10.713
@HelkaHomba Can you put up test cases in an easy-to-copy format? – mbomb007 – 2016-08-18T18:15:01.150