The trick isn't magic. A check like A=abs(B-K) will return 1 for K=B+A and K=B-A.

If we upgrade it to A=abs(B-abs(C-K)), this checks for abs(C-K) being equal to B+A and B-A, which in turn means K is one of:

Unfortunately, not every group of 4 values can be expressed like this. For instance, 15, 21, 45, and 105 can't.

If we're dealing with key values, we might take a group of 3 values and add in a fourth one that would work with this trick, but isn't actually a valid key. For example, if we have 15, 45, and 105, we might add in 135.

- We already know that 45 and 105 can be checked for by 30=abs(75-K).
- Similarly, 15 and 135 can be checked for by 60=abs(75-K).
- So now we check for abs(75-K) being 30 or 60. Call this value L for short.
- L=30 or L=60 can be checked for by 15=abs(45-L).
- Now we substitute in what L actually is…
- …to get 15=abs(45-abs(75-K)).

This is one byte shorter than the universally-useful alternative: max(K={15,45,105}). Unfortunately, it's also ridiculously incomprehensible, and can't be easily changed if, say, you decide you also want to check for 21, or if you decide that 11 is a better value than 15.

I suggest you use max(K={A,B,C,…}) to check for multiple values of K, and don't worry about using abs(.