Created
June 21, 2012 23:27
-
-
Save bltavares/2969234 to your computer and use it in GitHub Desktop.
WCC 2012.25 + 2012.26
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
import Data.Bits | |
mySum :: Int -> Int -> Int | |
mySum a b | |
|carry == 0 = result | |
|otherwise = mySum result $ shift carry 1 | |
where carry = (.&.) a b | |
result = xor a b | |
mySubtraction :: Int -> Int -> Int | |
mySubtraction a b = mySum a $ mySum 1 $ complement b | |
main = do | |
print $ mySum 1 2 | |
print $ mySum 15 50 | |
print $ mySum 100 100 | |
print $ mySum 100 (- 100) | |
print $ mySubtraction 100 100 | |
print $ mySubtraction 100 (- 100) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment