formula made of 0, 1, & (AND), | (OR) and parentheses. The formula is well formed: parentheses are balanced, there are no empty parentheses, and operands alternate with operators.
Operators have no precedence: parentheses are evaluated first, and inside them operators are applied strictly from left to right. For example, 1|0&0 means (1|0)&0 = 0.
One change turns a 0 into a 1 or back, or an & into a | or back. Return the smallest number of changes that makes the whole formula evaluate to the opposite of its current value.formula="0|1&0" → 1
Evaluating left to right: (0|1)&0 = 1&0 = 0. Replace the last 0 with 1: (0|1)&1 = 1. One change is enough.
formula="(1&1)|(1&1)" → 2
The value is 1 now. To get 0, either switch off both brackets (one change each) or turn | into & and switch off one bracket. Both ways take 2 changes.
formula="1" → 1
Just change the only symbol: 1 → 0.
formula contains only 0, 1, &, |, (, )()formula="0|1&0"
1
Run checks the first 3 tests in your browser. Submit checks all 175 tests on the server, hidden ones included.