Is this square symmetrical? Write a program or function that takes in a 4&times;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&deg; rotational symmetry. e.g.

BDAB
ACCD    same if rotated 90 degrees (or 180 or 270)
DCCA
BADB

If there is 180&deg; 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.
CJam, 16 bytes

{{z_W%_}4*;])e=}


An unnamed block which expects the input as a list of four strings on top of the stack and leaves a 0 (falsy) for asymmetric inputs and a positive integer (truthy) for symmetric inputs.

Test it here. Or run a full test suite.

Explanation

The symmetries of the square are the elements of the dihedral group of order 8 (which are just the 4 rotations of the square and the same 4 rotations of some reflected version of the square). It's not possible to generate this group from repeated application of a single permutation. But two reflections always give some rotation. Hence, the entire group can be generated by alternating between two reflections four times. (We just need to make sure that the two reflections give the 90 degree or 270 degree rotation, not 0 or 180.)

The challenge asks whether the input square is equal to any of the other 7 symmetries. So this answer just generates all of them and then checks whether the input is among the others.

{      e# Run this block 4 times.
  z_   e# Transpose the grid and duplicate it. (This is one type of reflection.)
  W%_  e# Reverse the lines and duplicate it. (This is another type of
       e# reflection. Together they rotate the grid by 90 degrees.)
}4*    e# The last element will be the original grid again.
;      e# Discard one copy of that original grid.
]      e# Wrap all symmetries in a list.
)      e# Pull off the original grid.
e=     e# Count how many times it appears among the other symmetries.


To see how the repeated application of z and W% generates all symmetries, have a look at this "diagram":

     0123
     4567
     89ab
     cdef

     original

 z   048c       W%       37bf
--&gt;  159d  -----------&gt;  26ae
     26ae                159d
     37bf                048c

     diag. refl.         rot. 90 degrees ccw

 z   3210       W%       fedc
--&gt;  7654  -----------&gt;  ba98
     ba98                7654
     fedc                3210

     vert. refl.        rot. 180 degrees

 z   fb73       W%       c840
--&gt;  ea62  -----------&gt;  d951
     d951                ea62
     c840                fb73

     antidiag. refl.     rot. 270 degrees ccw

 z   cdef       W%       0123
--&gt;  89ab  -----------&gt;  4567
     4567                89ab
     0123                cdef

     horiz. refl.        original