Skip to content

Instantly share code, notes, and snippets.

@chrislewis
Created November 6, 2019 22:29
Show Gist options
  • Save chrislewis/b89c65cb0e85b6b157e9d6f4f254d53a to your computer and use it in GitHub Desktop.
Save chrislewis/b89c65cb0e85b6b157e9d6f4f254d53a to your computer and use it in GitHub Desktop.
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