Hi.
I’m sorry, I have not made the good request
Actually my request is: if at least two datas has the value== 0, so all datas are 1. And if only one data has the value 0 we don’t have to change anything.
I don’t have to compare pair of datas but all datas at the same time. (but this option can be great for further research ;))
I put your former program below. I added real datas I want to compare in the setup in order to put them in the array original3 but i didn’t manage, it is not the good syntax.
int [] TrigmodPos = new int [12];
final int[]
original = { 1, 0, 1, 1, 1, 1, 1, 1, 1, 1},
cloned = original.clone();
final int[]
original2 = { 1, 0, 0, 1, 1, 1, 1, 1, 1, 1},
cloned2 = original2.clone();
final int[]
original3 = { 1, 0, 1, 0, 1, 1, 1, 1, 1, 1},
cloned3 = original3.clone();
boolean [] bools, bools2, bools3;
void setup() {
TrigmodPos[11]=1;
TrigmodPos[10]=0;
TrigmodPos[9]=1;
TrigmodPos[8]=0;
TrigmodPos[7]=1;
TrigmodPos[6]=1;
TrigmodPos[5]=1;
TrigmodPos[4]=1;
TrigmodPos[3]=1;
TrigmodPos[2]=1;
// original3 = {TrigmodPos[11], TrigmodPos[10], TrigmodPos[9], TrigmodPos[8], TrigmodPos[7],
// TrigmodPos[6], TrigmodPos[5], TrigmodPos[4], TrigmodPos[3], TrigmodPos[2]};
println(ifAll0SetTo1(cloned, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9)); //
// println(ifAll0SetTo1(cloned, new int[] { 1, 2 })); // false
println(str(original));
println(str(cloned));
bools = boolean(cloned);
println(str(bools));
println(ifAll0SetTo1(cloned2, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9)); //
// println(ifAll0SetTo1(cloned2, new int[] { 1, 2 })); // false
println(str(original2));
println(str(cloned2));
bools2 = boolean(cloned2);
println(str(bools2));
println(ifAll0SetTo1(cloned3, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9)); //
// println(ifAll0SetTo1(cloned3, new int[] { 1, 2 })); // false
println(str(original3));
println(str(cloned3));
bools3 = boolean(cloned3);
println(str(bools3));
exit();
}
@SafeVarargs static final boolean
ifAll0SetTo1(final byte[] arr, final int... indices)
{
assert arr.length * indices.length != 0: "Array argument is empty";
final boolean allZero;
int sum = 0;
for (final int idx : indices) sum += arr[idx];
if (allZero = sum == 0) for (final int idx : indices) arr[idx] = 1;
return allZero;
}
@SafeVarargs static final boolean
ifAll0SetTo1(final int[] arr, final int... indices)
{
assert arr.length * indices.length != 0: "Array argument is empty";
final boolean allZero;
int sum = 0;
for (final int idx : indices) sum += arr[idx];
if (allZero = sum == 0) for (final int idx : indices) arr[idx] = 1;
return allZero;
}