I have an array a of 10 booleans (or equivalently the binary representation of a number < 1024). I want to compare this array to a large set of arrays b[i] of booleans of the same size in the following way:
The function compare(a,b[i]) should return true if the elements of the array a are never true when the element of at the same position in b[i] is false.
As an exemple in java
boolean compare(boolean a1, boolean a2){
for (int j = 0; j<10; j++)
if (a1[j] && !a2[j])
return false;
return true;
}
Is there a better implementation of this function? If one consider the corresponding binary number to be the coefficients of the prime decomposition of a integer A1 (and A2), an equivalent function would be
boolean compare (int A1, int A2){
if (gcd(A1,A2)==A1)
return true;
else
return false;
}
with for example, (http://www.java-tips.org/java-se-tips/java.lang/finding-greatest-common-divisor-recursively.html)
int gcd(int a, int b) {
if (b==0)
return a;
else
return gcd(b, a % b);
}
but I don’t think that this is more efficient (but I may be wrong).
Does anyone has an idea ? All suggestions are welcome!
EDIT: I will go back with some profiling later… Thanks for all your propositions!
If you can use integers instead of arrays, why not just: