Skip to content

Instantly share code, notes, and snippets.

@bltavares
Created June 21, 2012 23:27
Show Gist options
  • Save bltavares/2969234 to your computer and use it in GitHub Desktop.
Save bltavares/2969234 to your computer and use it in GitHub Desktop.
WCC 2012.25 + 2012.26
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