Created
May 15, 2018 01:44
-
-
Save msszczep/0bcc180eb341ce6e8b43d81fde4530a9 to your computer and use it in GitHub Desktop.
letters->numbers in Clojure, Take 2
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
(defn l->n [input] | |
"Given a string and the sequence a = 1, b = 2, ... z = 26, compute the total for the string. | |
Get a bonus point if the sequence 'zachary' appears in the string." | |
(let [point-values (zipmap (map char "abcdefghijklmnopqrstuvwxyz") | |
(range 1 27)) | |
bonus-point (if (re-find #"zachary" (clojure.string/lower-case input)) 1 0)] | |
(->> input | |
(map char) | |
(map point-values) | |
(cons bonus-point) | |
(reduce +)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment