Skip to content

Instantly share code, notes, and snippets.

@dhanji
Last active August 29, 2015 14:07
Show Gist options
  • Select an option

  • Save dhanji/f09da6bc5921f3c316b8 to your computer and use it in GitHub Desktop.

Select an option

Save dhanji/f09da6bc5921f3c316b8 to your computer and use it in GitHub Desktop.
Add two big integers
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
@dhanji
Copy link
Copy Markdown
Author

dhanji commented Oct 9, 2014

addBigInts "999999999999999999" "99999999999999999"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment