Skip to content

Instantly share code, notes, and snippets.

@chrislewis
Created November 7, 2019 02:17
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/c5397751e9e124e2941c9ba373601090 to your computer and use it in GitHub Desktop.
Save chrislewis/c5397751e9e124e2941c9ba373601090 to your computer and use it in GitHub Desktop.
sumTwoTrailRec (x : xs) (y : ys) total carry =
sumTwoTrailRec xs ys ((mod sum 10) : total) nextCarry where
sum = x + y + carry
nextCarry = div sum 10
sumTwoTrailRec (x : xs) [] total carry =
sumTwoTrailRec xs [] ((mod (x + carry) 10) : total) (div (x + carry) 10)
sumTwoTrailRec [] (y : ys) total carry =
sumTwoTrailRec [] ys ((mod (y + carry) 10) : total) (div (y + carry) 10)
sumTwoTrailRec [] [] total carry =
reverse $ if carry > 0 then (carry : total) else total
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment