I agree with others that there are many ways to simplify your code, but if you just want to simplify the if
statement you can do this:
if (!(x.contains("6"))
&& A1*B1*C1==6 && A2*B2*C2==6 && A3*B3*C3==6
&& A1*A2*A3==6 && B1*B2*B3==6 && C1*C2*C3==6)
The reason this works is that the only bags of three positive integers that multiply out to 6 are {1, 2, 3}
and {1, 1, 6}
, so if we exclude 6 from the start, every row and column must contain 1, 2 and 3.
4
solved Anyway I can shorten this IF statement? [closed]