Last active
May 22, 2019 15:24
-
-
Save mredig/fda4723eee24772298dc356b16e9ff80 to your computer and use it in GitHub Desktop.
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 Foundation | |
func AND(_ a: Bool, _ b: Bool) -> Bool { | |
if a == true { | |
if b == true { | |
return true | |
} | |
} | |
return false | |
} | |
AND(true, true) // returns true | |
AND(true, false) // returns false | |
AND(false, true) // returns false | |
AND(false, false) // returns false | |
func NOT(_ a: Bool) -> Bool { | |
//tempted to use toggle, but said we are limited to only ifs | |
if a == true { | |
return false | |
} | |
return true | |
} | |
NOT(true) //false | |
NOT(false) //true | |
func NAND(_ a: Bool, _ b: Bool) -> Bool { | |
if a == true { | |
if b == true { | |
return false | |
} | |
} | |
return true | |
} | |
NAND(true, true) // returns false | |
NAND(true, false) // returns true | |
NAND(false, true) // returns true | |
NAND(false, false) // returns true | |
func IOR(_ a: Bool, _ b: Bool) -> Bool { | |
if a == true { | |
return true | |
} | |
if b == true { | |
return true | |
} | |
return false | |
} | |
IOR(true, true) //true | |
IOR(true, false) //true | |
IOR(false, true) //true | |
IOR(false, false) //false | |
func XOR(_ a: Bool, _ b: Bool) -> Bool { | |
if a == b { | |
return false | |
} | |
return true | |
} | |
XOR(true, true) //false | |
XOR(true, false) //true | |
XOR(false, true) //true | |
XOR(false, false) //false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment