Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Coding puzzle
Message
 
To
04/06/2002 10:55:28
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivia
General information
Forum:
Visual FoxPro
Category:
Other
Title:
Miscellaneous
Thread ID:
00664411
Message ID:
00664515
Views:
32
>>>How do you simplify the following VFP expression?
>>>
>>>
>>>(A and not B) or (B and not A)
>>>
>>>
>>>(I wasn't sure whether I should place this in "Chatter | Puzzles", or in "VFP | Chatter...". Anyway, I know the answer to this one, but wanted to present it to the community, as a puzzle.)
>>>
>>Hilmar,
(A # B)
>
>Yes, that is the answer. I usually code this as follows:
>
>
>#define XOR #
>...
>if A XOR B
>  ...
>
>
>The equivalency can be established through truth tables, which I will include here for others who read this thread:
>
>
>
>A  B  !A  !B  (1)  (2)  (3)   A#B
>T  T   F   F   F    F    F     F
>T  F   F   T   T    F    T     T
>F  T   T   F   F    T    T     T
>F  F   T   T   F    F    F     F
>
>(1): A AND NOT B
>(2): B AND NOT A
>(3): (1) OR (2)
>
>
>As you can see, the last two columns are equivalent.
>
Hilmar,

Ye olde truth table always comes through. Actually, just looking at it told me two things. First, that there were only four possible values for the combination of A and B. Second, because the expressions on each side of the OR operator were logically opposite, I could throw away having to evaluate the expressions where they (A and B) were equal to each other. That's half of the four possibilities and left only those two where the values are not equal to each other.
George

Ubi caritas et amor, deus ibi est
Previous
Reply
Map
View

Click here to load this message in the networking platform