This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data Op = Plus | Minus | Concat deriving Show | |
f l = concatMap (\r -> map (: r) l) | |
step :: Int -> Op -> (Int, Int) -> (Int, Int) | |
step digit op (carry, sum) = case op of | |
Concat -> (digit * 10 ^ ceiling (logBase 10 (fromIntegral carry)) + carry, sum) | |
Plus -> (digit, sum + carry) | |
Minus -> (digit, sum - carry) |