Math is a big part of programming. This exercise is meant to be completed visually, not with the aid of the computer.
If you have not studied multiplication of negative numbers then you will be at a bit of a disadvantage with this one.
-1 * -1 == 1
-1 * 1 == -1
A negative times a negative yields a positive product.
A negaive times a positive yields a negative product.
A negative sign on a number is the same as
-1 times the positive number.
-22 == -1 * 22
That shows that wherever we see a negative sign we can insert a
-1 * -1 * -1 * -1 * 2
Now count the negative 1’s. Four in all. When the number of negatives is even, the product is positive. When the number of negatives is odd, the product is negative.
The above can be reduced to
1 * 2 which is
Now let’s consider the
and operator. These expressions short-circuiton
False, meaning ALL operands must yield True or the expression will yield False.
2 == -2 => False
The rest of the expression is ignored since the first operand is False.