-- http://www.codewars.com/kata/51b62bf6a9c58071c600001b
module RomanNumerals where

helper m d c n
  | n<=3 = replicate n c
  | n==4 = [c, d]
  | n<=8 = d : replicate (n-5) c
  | n==9 = [c, m]

solution :: Integral a => a -> String
solution n =
  helper undefined undefined 'M' m
  ++ helper 'M' 'D' 'C' c
  ++ helper 'C' 'L' 'X' x
  ++ helper 'X' 'V' 'I' i where
    (i:x:c:m:_) = (map (fromIntegral . (`mod` 10)) . iterate (`div` 10)) n
