Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.