Skip to content

Instantly share code, notes, and snippets.

@msszczep
Created May 15, 2018 01:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msszczep/0bcc180eb341ce6e8b43d81fde4530a9 to your computer and use it in GitHub Desktop.
Save msszczep/0bcc180eb341ce6e8b43d81fde4530a9 to your computer and use it in GitHub Desktop.
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