Solution: The initial status is unknown, but definitely it is not 4 "1" or "0". Try to think from the last step (under what condition, you can definitely open the box with one more move). We can do as follow:
- Set two adjacent locks to "0", if still not open, go to step 2.
- Set two locks that are opposite to each other to "0", if still not open, go to step 3.
- If you reach here, it means there is one "1" and three "0". Try two adjacent locks, if one is '1" and one is "0", Bingo! Set the "1" to "0". But if you encounter two "0", you need to set one of them to "1". Then there are two cases: a) "1 0 1 0" and b) "1 1 0 0". Let's go to step 4.
- if it is a), then we try to set two locks that are opposite to each other to either "0" or "1". We are done! If it is b), we still try to set two locks that are opposite to each other. Basically, we just toggle them (or do nothing). Then step 5.
- So we still have "1 1 0 0". This time try to set two adjacent locks, if we encounter two "1" or two "0", we are done. If not, we toggle them. Then we have "1 0 1 0". Then go to step 5.
- Try to set two locks that are opposite to each other, we got the treasure.
- Toggle two opposite ones.
- Toggle two adjacent ones.
- Toggle two opposite ones.
- Toggle a random one.
- Toggle two opposite ones.
- Toggle two adjacent ones.
- Toggle two opposite ones.
No comments:
Post a Comment