Skip to content

Instantly share code, notes, and snippets.

@chrislewis
Created November 6, 2019 22:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrislewis/7ccbe31e6019c9b76439dcc5b1cd05b8 to your computer and use it in GitHub Desktop.
Save chrislewis/7ccbe31e6019c9b76439dcc5b1cd05b8 to your computer and use it in GitHub Desktop.
sumTwo :: [Int] -> [Int] -> [Int]
sumTwo x y = doit x y [] 0
where
doit [] [] sum 0 = reverse sum
doit [] [] sum carry = doit [] [] (carry : sum) 0
doit (x : xs) (y : ys) sum carry =
let tot = x + y + carry
(n, nc) =
if tot > 9
then (tot - 10, 1)
else (tot, 0)
in doit xs ys (n : sum) nc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment