Created
October 8, 2014 04:52
-
-
Save andrewrk/a4bf9e6bb399e43f5e3f 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
A = B = True | |
X = Y = False | |
problems = ( | |
lambda P,Q: A or P, | |
lambda P,Q: Q and X, | |
lambda P,Q: Q or not X, | |
lambda P,Q: not B and P, | |
lambda P,Q: P or not P, | |
lambda P,Q: not P or (Q or P), | |
lambda P,Q: Q and not Q, | |
lambda P,Q: P and (not P or X), | |
lambda P,Q: not (P and Q) or P, | |
lambda P,Q: not Q and ((P or Q) and not P), | |
lambda P,Q: (P or Q) and not (Q or P), | |
lambda P,Q: (P and Q) and (not P or not Q), | |
lambda P,Q: not P or (not Q or (P and Q)), | |
lambda P,Q: P or not (not A or X), | |
lambda P,Q: P and (not(P or Q) or not P), | |
lambda P,Q: not (P and Q) or (Q and P), | |
lambda P,Q: not(not(not P or Q) or P) or P, | |
lambda P,Q: (not P or Q) and not(not P or (P and Q)), | |
lambda P,Q: (not A or P) and (not P or Y), | |
lambda P,Q: not(P or (B and Y)) or ((P or B) and (P or Y)), | |
lambda P,Q: (P or (Q and A)) and not ((P or Q) and (P or A)), | |
lambda P,Q: (P or (Q and X)) and not ((P or Q) and (P or X)), | |
lambda P,Q: not(not P or (not Q or X)) or (not(not P or Q) or (not P or X)), | |
lambda P,Q: not(not P or (not Q or A)) or (not(not P or Q) or (not P or A)), | |
lambda P,Q: not((P and Q) or (Q and not P)) and not ((P and not Q) or (not Q and not P)), | |
) | |
print("PHI103 Homework 6.2 Exercises Part C") | |
for index, problem in enumerate(problems): | |
# execute for each possibility of P and Q | |
result = {} | |
print("Problem " + str(index+1) + ":") | |
print("P\tQ\tAnswer") | |
for P in (True, False): | |
for Q in (True, False): | |
ret = problem(P,Q) | |
result[str(P)+str(Q)] = ret | |
print(str(P) + "\t" + str(Q) + "\t" + str(ret)) | |
# print value if any | |
if result['TrueTrue'] == result['TrueFalse'] == result['FalseTrue'] == result['FalseFalse']: | |
print("Can be determined; the answer is " + str(result['TrueTrue'])) | |
else: | |
print("Result cannot be determined for sure.") | |
print("") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment