I have 4 switches that are randomly generated at run time. Ex:
Switch1: 1 0 0 0
Switch2: 0 1 0 0
Switch3: 0 0 1 0
Switch4: 0 0 0 1
When the switch is generated, the column for the switch number needs to be 1, but all other columns are randomly assigned (1 or 0).
A main switch performs an XOR operation on a switch that the user selects. The main switch starts at 0 0 0 0.
When the user selects a switch ( s1,s2,s3,s4 ) it is "XOR"ed to the current main switch.
Real Case:
S1: 1 1 0 0
S2: 0 1 1 0
S3: 0 0 1 0
S4: 1 0 0 1
START: 0 0 0 0
AND S1:1 1 0 0
AND S3:1 1 1 0
The objective is to get the main switch to 1 1 1 1.
When the four switches are created at run-time, I need to ensure that the puzzle is solvable. Any suggestions on how I can compare the four switches to determine if there is a combination to achieve a winning result of 1 1 1 1.
UPDATE------------
Note:
0 and 0 = 0
1 and 1 = 0
0 and 1 = 1
If you start with
0000
and the only operation available is AND, you cannot get anything except0000
as a result:0 & 1 = 0
, not0 & 1 = 1
.Based on the example in your Real Case, it appears that you are performing an OR operation. If this is the case then any puzzle is solvable since
If you OR each switch with the original
0000
main switch you will always get1111
. You may get it before OR'ing with all four switches, based on the other randomly assigned bits, but you are guaranteed to get1111
if you OR each switch with the original main switch.