fork download
  1. import Data.List
  2.  
  3. main :: IO ()
  4. main = putStr
  5. . filter (isPandigital . toRoman)
  6. $ [1..2000]
  7.  
  8. toRoman :: Int -> String
  9. toRoman = toRoman'
  10. [ (1000, "M"), (900, "CM"), (500, "D"), (400, "CD")
  11. , (100, "C"), (90, "XC"), (50, "L"), (40, "XL")
  12. , (10, "X"), (9, "IX"), (5, "V"), (4, "IV"), (1, "I")
  13. ]
  14. where
  15. toRoman' :: [(Int, String)] -> Int -> String
  16. toRoman' _ 0 = ""
  17. toRoman' [] _ = error "Empty roman numerals"
  18. toRoman' ((y,r):ys) x
  19. | x < y = toRoman' ys x
  20. | otherwise = r ++ toRoman' ((y,r):ys) (x - y)
  21.  
  22. isPandigital :: String -> Bool
  23. isPandigital = (== "CDILMVX") . sort
Success #stdin #stdout 0s 8388607KB
stdin
Standard input is empty
stdout
1444
1446
1464
1466
1644
1646
1664
1666