Created
November 6, 2019 22:29
-
-
Save chrislewis/b89c65cb0e85b6b157e9d6f4f254d53a 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
sumTwoFoldl :: [Int] -> [Int] -> [Int] | |
sumTwoFoldl x y = | |
let (sum, carry) = foldl accum ([], 0) $ zip x y | |
accum (total, carry) (x, y) = | |
let t = x + y + carry | |
(n, nc) = | |
if t > 9 | |
then (t - 10, 1) | |
else (t, 0) | |
in (n : total, nc) | |
final = | |
if carry > 0 | |
then carry : sum | |
else sum | |
in reverse final |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment