Symmetry
We need to classify patterns into four different categories:
- horizontally symmetrical
- vertically symmetrical
- perfect (both vertically and horizontally symmetrical)
- imperfect (neither vertically nor horizontally symmetrical)
Patterns are two-dimmensional. We will represent them with vectors of vectors. Each inner vector is a row.
Write a function classify
that takes a pattern and returns one of :vertical
, :horizontal
, :perfect
, or :imperfect
.
Examples
(classify [["a" "b" "a"]
["x" "y" "x"]]) ;=> :horizontal
(classify [["a" "b" "c"]]) ;=> :vertical ;; trivially so
(classify [["a" "b" "a"]
["y" "X" "y"]
["a" "b" "a"]]) ;=> :perfect
UPDATE: I have horizontal and vertical switched accidentally, but I won't change it since people have already submitted.
Thanks to this site for the challenge idea where it is considered Expert level in JavaScript.
Nice job everyone!
It seems almost everyone went with the examples of the problem description in this gist, rather than the site which inspired it - essentially the meanings of :horizontal and :vertical are reversed, (reflecting across a dividing axis orthogonal to the dimension as in the original, vs the dimension of the line linking reflected values as in this gist). I chose the original as it seems more intuitive.
Here are my findings for most solutions against my own tests (see previous post above) - including a few odd errors on empty lists.
If you followed this gist's examples, then it makes sense that they appear reversed. If your name doesn't appear, all my tests passed but would fail against this gist's examples.