Created
December 8, 2011 06:43
-
-
Save anonymous/1446303 to your computer and use it in GitHub Desktop.
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
;; 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