Skip to content

Instantly share code, notes, and snippets.

Created May 15, 2018
What would you like to do?
letters->numbers in Clojure, Take 2
(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