Reputation: 11
How can I check if 3 natural numbers are not equal (at all), 2 of the 3 are equals or all of them are equal?
The last one makes perfect sense but I am confused because of the first two. How do I check whether 2 of 3 are equal?
I had a function (define-struct (func1 num1))
I used not (= (struct-num1) (struct-num2) (struct-num3))
But it returns true if 2 or 3 are equal.
Upvotes: 1
Views: 1101
Reputation: 22979
The straightforward way to check if three numbers are all different (e.g. 3 6 4) is to check that each pair is different:
(and (not (= a b)) (not (= a c)) (not (= b c)))
Checking that all three are equal (e.g. 4 4 4) you can do already.
If both checks return false, then exactly two must be equal (e.g. 3 6 3).
Upvotes: 1