Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Coding puzzle
Message
De
04/06/2002 10:55:28
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivie
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Titre:
Divers
Thread ID:
00664411
Message ID:
00664484
Vues:
20
>>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.
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform