Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Boolean Algebra by svn1991
# migrated from python 2.7
def conjunction(x,y):
return (x and y)
def disjunction(x,y):
return (x or y)
def implication(x,y):
if x:
return y
else:
return 1
def exclusive(x,y):
if conjunction(x,y) == disjunction(x,y):
return 0
else:
return 1
def equivalence(x,y):
if x == y:
return 1
else:
return 0
def boolean(x, y, operation):
OPERATION_NAMES = {"conjunction": conjunction(x,y),
"disjunction": disjunction(x,y),
"implication": implication(x,y),
"exclusive": exclusive(x,y),
"equivalence": equivalence(x,y)}
return OPERATION_NAMES[operation]
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert boolean(1, 0, "conjunction") == 0, "and"
assert boolean(1, 0, "disjunction") == 1, "or"
assert boolean(1, 1, "implication") == 1, "material"
assert boolean(0, 1, "exclusive") == 1, "xor"
assert boolean(0, 1, "equivalence") == 0, "same?"
April 10, 2016
Comments: