Created
July 7, 2012 16:46
-
-
Save epost/3067166 to your computer and use it in GitHub Desktop.
Mischa's adder
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
import Data.Digits | |
carry r i x y | i == 0 = 0 | |
| x + y + carry r (i-1) x y <= r-1 = 0 | |
| True = 1 | |
-- currently works iff x and y have same # of digits, due to zip3 | |
add x y = | |
sum [ (x_i + y_i + carry r i x y)*r^i | (x_i, y_i, i) <- (zip3 xs ys [0..])] | |
where r = 10 | |
xs = digits r x | |
ys = digits r y |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment