Skip to content

Instantly share code, notes, and snippets.

Created December 8, 2011 06:43
Show Gist options
  • Save anonymous/1446303 to your computer and use it in GitHub Desktop.
Save anonymous/1446303 to your computer and use it in GitHub Desktop.
;; flengyel's solution to Read Roman numerals
;; https://4clojure.com/problem/92
(fn [numeral] (-> (let [roman {\I 1, \V 5, \X 10, \L 50, \C 100, \D 500, \M 1000} digit (roman (first (vec numeral)))]
(reduce
(fn [[acc prv] cur] (let [nacc (+ acc cur)]
[(if (< prv cur) (- nacc (* 2 prv)) nacc) cur]))
[digit digit]
(map roman (rest (vec numeral))))) (first)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment