Created
November 6, 2019 22:28
-
-
Save chrislewis/7ccbe31e6019c9b76439dcc5b1cd05b8 to your computer and use it in GitHub Desktop.
This file contains 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
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