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"]]) ;=> :perfectUPDATE: 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.
Hi everyone,
I was confused about the challenge spec examples which seem wrong for both horizontal and vertical labels (it seems they should be vertical and horizontal resp., so tested everyone's solution so far against the below samples (and added @miner's [], [[]] contribution)
which confirms that these test features are accurate. Thanks!
EDIT: I did find some issues with several solutions - see later post.