Created
November 7, 2019 02:17
-
-
Save chrislewis/c5397751e9e124e2941c9ba373601090 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
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