Last active
August 29, 2015 14:07
-
-
Save dhanji/f09da6bc5921f3c316b8 to your computer and use it in GitHub Desktop.
Add two big integers
This file contains hidden or 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
add [] [] c = show c | |
add ls [] c = add ls (replicate (length ls) '0') c | |
add [] ls c = add (replicate (length ls) '0') ls c | |
add (x:xs) (y:ys) c = (add xs ys carry) ++ (show result) | |
where | |
addInt x y z = (read x :: Int) + (read y :: Int) + z | |
addition = addInt [x] [y] c | |
carry = addition `quot` 10 | |
result = addition `mod` 10 | |
addBigInts x y = add (reverse x) (reverse y) 0 | |
Author
dhanji
commented
Oct 9, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment