# Demo entry 6662543

**solving problem**

Submitted by **anonymous**
on Nov 26, 2017 at 18:40

Language: Python 3. Code size: 1.6 kB.

from pyeda.inter import * # Engineer and Salesman Questions # A to G stands for 7 people in the question # A = 1 if A is a salesman and A = 0 if A is an engineer and similarly for other people A, B, C, D, E, F, G = map (exprvar, 'ABCDEFG') # A is an engineer A = 0 # B is a salesman B = 1 # E is a salesman E = 1 # The first claim of C that “D is an engineer” H = ~D # The statement we want to check about the first claim is: S1 = C&H | ~C&~H # The claim of F in the second claim I = G # The statement we want to check about claim of F and is also the claim of E in the second claim S2 = F&~I | ~F&I # As E is a salesman, the statement we need to check about E is just equal to S2 # Therefore, S2 is also the claim of D in the second claim # The statement we want to check about claim of D and also the claim of C in the second claim S3 = D&S2 | ~D&~S2 # The statement we want to check about claim of C and also the claim of B in the second claim S4 = C&S3 | ~C&~S3 # As B is a salesman, the statement we need to check about B is just equal to S4 # Therefore, S4 is also the claim of A in the second claim # As A is an engineer, the statement we need to check about A is: S5 = ~S4 #Both of S5 and S1 should be true S = S5 & S1 # Solve the question print ("The possible situations are: ") for x in S.satisfy_all(): print(x) {G: 1, F: 0, D: 1, C: 0} {G: 0, F: 1, D: 1, C: 0} {G: 1, F: 0, D: 0, C: 1} {G: 0, F: 1, D: 0, C: 1} # As shown in the output, there are always 2 of them are engineers and other 2 are salesmen. Therefore, the number of engineers should be 3 and the number of salesmen should be 4.

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.