Skip to content

Instantly share code, notes, and snippets.

@mredig
Last active May 22, 2019 15:24
Show Gist options
  • Save mredig/fda4723eee24772298dc356b16e9ff80 to your computer and use it in GitHub Desktop.
Save mredig/fda4723eee24772298dc356b16e9ff80 to your computer and use it in GitHub Desktop.
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