Skip to content

Instantly share code, notes, and snippets.

View niuk's full-sized avatar

Kangyuan Niu niuk

View GitHub Profile
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)