Skip to content

Instantly share code, notes, and snippets.

@david-hodgetts
Last active December 16, 2015 03:09
Show Gist options
  • Save david-hodgetts/5367378 to your computer and use it in GitHub Desktop.
Save david-hodgetts/5367378 to your computer and use it in GitHub Desktop.
4Clojure problem 92 (Take One)
(fn roman
([s] (roman (seq s) 0))
([s v]
(let [c1 (first s)
c2 (second s)
c12 (list c1 c2)]
(if (empty? s) v
(cond
(= c12 '(\I \V)) (roman (drop 2 s) (+ v 4))
(= c12 '(\I \X)) (roman (drop 2 s) (+ v 9))
(= c12 '(\X \L)) (roman (drop 2 s) (+ v 40))
(= c12 '(\X \C)) (roman (drop 2 s) (+ v 90))
(= c12 '(\C \D)) (roman (drop 2 s) (+ v 400))
(= c12 '(\C \M)) (roman (drop 2 s) (+ v 900))
(= c1 \M) (roman (rest s) (+ v 1000))
(= c1 \D) (roman (rest s) (+ v 500))
(= c1 \C) (roman (rest s) (+ v 100))
(= c1 \L) (roman (rest s) (+ v 50))
(= c1 \X) (roman (rest s) (+ v 10))
(= c1 \V) (roman (rest s) (+ v 5))
(= c1 \I) (roman (rest s) (+ v 1))
)
)
)
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment