Permalink
Browse files

Use a conversions table for scalable logic

  • Loading branch information...
adomokos committed Nov 5, 2018
1 parent 75f0403 commit 76693b3da61eae126a6c70e76630ae54e266100e
Showing with 12 additions and 4 deletions.
  1. +12 −4 test/RomanNumeralsSpec.hs
@@ -6,12 +6,20 @@ main :: IO ()
main = hspec spec
type Roman = String
type Conversions = [(Int, Roman)]
conversions :: Conversions
conversions =
[ (4, "IV")
, (1, "I") ]
convertToRoman :: Int -> Roman
convertToRoman 1 = "I"
convertToRoman 2 = "II"
convertToRoman 3 = "III"
convertToRoman 4 = "IV"
convertToRoman 0 = []
convertToRoman x =
roman ++ convertToRoman (x - number)
where
(number, roman) =
head . filter (\(a,_) -> a <= x) $ conversions
convertFromRoman :: Roman -> Int
convertFromRoman "" = undefined

0 comments on commit 76693b3

Please sign in to comment.