Last active
September 27, 2017 12:15
-
-
Save pataprogramming/fab15287ae8103f154dc1508afc4d340 to your computer and use it in GitHub Desktop.
PhillyDev Slack #daily_programmer 2017-09-26 - Symmetrical Strings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(let [symmetrical-chars "!\"'+*-.:=AHIMOTUVWXY^_ovwx| " | |
symmetrical-pairs "()<>[]{}qpbd/\\" | |
lookup-table (->> symmetrical-pairs | |
((juxt seq reverse)) | |
(apply concat) | |
(partition 2) | |
(map vec) | |
(into {}) | |
(merge (zipmap symmetrical-chars | |
symmetrical-chars)))] | |
(defn symmetrical-pair? [[a b]] | |
(= b (get lookup-table a)))) | |
(defn symmetrical? [s] | |
(let [n (inc (/ (count s) 2))] | |
(every? symmetrical-pair? (map vector (take n s) (take n (reverse s)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment