2016 Update

This commit is contained in:
Tina Müller 2016-12-05 22:15:40 +01:00
parent 948b86eafa
commit dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions

View file

@ -0,0 +1,16 @@
import Data.List (mapAccumL, isPrefixOf)
romanValue :: String -> Int
romanValue s = sum . snd $ mapAccumL tr s
[("M", 1000), ("CM", 900), ("D", 500), ("CD", 400),
("C", 100), ("XC", 90) ,("L", 50), ("XL", 40),
("X", 10), ("IX", 9), ("V", 5), ("IV", 4),
("I", 1)]
where
tr s (k, v) =
until (\(s, _) -> not $ isPrefixOf k s)
(\(s, n) -> (drop (length k) s, n + v)) (s, 0)
main :: IO ()
main = mapM_ (putStrLn . show . romanValue)
["MDCLXVI", "MCMXC", "MMVIII", "MMXVI", "MMXVII"]