import Data.List main :: IO () main = putStr . unlines . map show . filter (isPandigital . toRoman) $ [1..2000] toRoman :: Int -> String toRoman = toRoman' [ (1000, "M"), (900, "CM"), (500, "D"), (400, "CD") , (100, "C"), (90, "XC"), (50, "L"), (40, "XL") , (10, "X"), (9, "IX"), (5, "V"), (4, "IV"), (1, "I") ] where toRoman' :: [(Int, String)] -> Int -> String toRoman' _ 0 = "" toRoman' [] _ = error "Empty roman numerals" toRoman' ((y,r):ys) x | x < y = toRoman' ys x | otherwise = r ++ toRoman' ((y,r):ys) (x - y) isPandigital :: String -> Bool isPandigital = (== "CDILMVX") . sort