Deceptively simple algorithm question I came across. I’m trying to pull it off in 3 or less operations, and I’m reasonably convinced it can be solved with math, but I can’t figure it out (and the source for the question didn’t have an answer).
EDIT:
(a[0] == a[1] + a[0] == a[2] + a[1] == a[2]) == 1
is what I originally thought, but I’d like to see if it can be done in less operations (1 comparison being an operation).
Assuming the 3 numbers are
a,bandc,b == c(true) and thena != c(false) and done.b == c(false) and thena == b(true) and done.b == c(false) and thena == b(false) anda == c(true) and done.b == c(true) and thena != c(true) and done.b == c(false) and thena == b(false) anda == c(false) and done.So at most 3 comparison are performed.
There are also 2 conditional branching points at
?:and||but OP does not count it.