Does anyone know any efficient ways to check if any set of integers contains an integer that has changed by a certain amount.
For example I have:
int1 = 10;
int2 = 20;
int3 = 30;
And I want to know if any of these 3 integers change by 30
Now if int1
becomes 40
than the call should be triggered. At first I thought of just doing something like this.
if (abs((int1+int2+int3)-(newInt1+newInt2+newInt3)) >= 30) {
But many problems can arise from this...
- False triggers (e.g. each new int value increases by 10, making the NET change greater than 30 but not necessarily any individual int greater than 30)
- Untriggered reactions (e.g. one of the new integer values has increased by 50 so it should be called but then another new integer value is decreased by 50 (again, it should be called) but the net change is now zero because
-50+50=0
)
Does anyone have any efficient way of doing this? (Yes, I know obviously I could just check each value individually with OR statements...)
So far this is my best stab at it
if ((((abs(int1-newInt1))>=30)+((abs(int2-newInt2))>=30)+((abs(int3-newInt3))>=30))>0) {
But that's basically the same as using an OR statement (probably even takes a little longer than an OR statment.