Peggy is a treasure hunter trying to open two treasure boxes. One box has 2 switches and the other has 4 switches. All of the switches are initially turned off. To open a treasure box,
Peggy successfully opens the box with 2 switches in the following manner:
The sequence in which Peggy toggles the switches
Can Peggy open the box with 4 switches?
Hint: What if Peggy's box had 3 switches instead?
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
Grey codes are useful in digital communications. For example:
Suppose someone is sending a series of numbers representing positions on a line segment. If the numbers are coded by a Grey Code sequence with 2-bit numbers representing positions from left to right (as opposed to just using the sequence 1, 2, 3, 4 converted into binary) then any 1-bit error will be spatially adjacent to the correct position. This makes it easier to create an error correction system.
The 4-bit version is used in 2-dimensional applications in a similar way.
Thank you for the information on Gray codes! I learned something new.
To generate A n from A n − 1 , change the m th bit, where 2 m is the greatest power of two dividing n .
I think it'd be helpful if you illustrated this with an example
@ Challenge Master note: I have to disagree with the last statement that "any 1-bit error will be spatially adjacent to the correct position". For instance, in the example table I gave, 0 1 0 1 corresponds to position 6, but 1 1 0 1 (which is only one bit off) corresponds to position 9, and 0 0 0 1 (also one bit off) corresponds to position 1.
Log in to reply
@Arjen Sorry, the 4-bit version is 2-D (which tends to be how it is often used). I was trying to explain a simpler version in 1-D which would be just four numbers -- I've tweaked the text to reflect the difference.
I am a secondary school student . Can you explain me
What are grey codes
Please have someone who does not know the answer READ the question. Both the question and the illustration refer to an end state - or at least that is the way it reads. Your answer refers to 2^n combination of n bits for setting the combs. Nowhere in the problem statement (at face value) is there any information about order of of setting the switches or requirements for the full application of adjacent switch differences. The main reason people who know math miss word problems is that they answer what was written and not what is meant.
Log in to reply
The problem is not merely talking about "an end state", because it says that Peggy "needs to register every possible combination exactly once". I don't see a discrepancy between what was written and what was (supposedly) meant.
I am one of the people who read the problem without knowing the answer. Only after carefully reading the "rules" of the game, I realized it tied in with math familiar to me--Grey codes, in this case.
Relevant wiki: Induction - Combinatorics Applications
Suppose it is possible for n switches, we will prove it is also possible for n + 1 switches.
For n+1 switches:
Step 1: set the first switch to Off
Step 2: for the remaining n switches, follow the exact sequence of combinations used in the solution for n switches.
Step 3: turn the first switch to On
Step 4: for the remaining n switches, follow in reverse order the exact sequence of combinations that were used in Step 2.
Neat observation, indeed.
Noticing that pattern was how I solved it, too! Since for n = 1 the sequence is trivially easy to find, solutions for increasing n can be quickly built up. It would be easier if you edited steps 2 and 4 to read something like: "Step 2: for the remaining n switches, follow the exact sequence of combinations used in the solution for n switches. Step 4: for the remaining n switches, follow in reverse order the exact sequence of combinations that were used in Step 2.
To beginning mathematicians out there who don't have any idea as to what Arjen Vreugdenhil is saying (it is a great solution I admit), this will be one of the possible solutions.
"F" would be Off and "T" would be On
Notice the pattern. 2^2 possible permutations of the last two switches. Notice that we didn't change the 1st and 2nd switches. We are only finding for the permutations for the two switches.
2^3=8 permutations for all the last three switches. Why? Because We changed the 2nd Switch and then again we find the permutations of the last two switches.
Then, repeating the iteration, now with the first switched on, we get another 8 permuations. Why? Because we are doing what we did in steps one to eight, with one exception, the first switch is ON.
To generalize, we need 2^n individual steps to find all the possible permutations without repeating one. Here, n=4, so we need 2^n = 2^4 = 16 steps. The base 2 is from the fact that there is two possible choices for a single switch, that are, ON and OFF.
Forgive me as this is not a proof. Tung Phung has already given one. I am trying to let beginner math students to understand.
Every switch has two choices on or off since these events happen together we can apply multiplication rule of combinatorics to get 2✖️2✖️2✖️.... n times to get 2^n
The hint was 'what if the box had 3 switches'. Well if it had 3 switches, then Peggy should do what she had done for the 2 switches. Then turn the 3rd switch. Then do exactly the reverse of the turns for the 2 switches. And now seeing as it has 4 switches, and we know that all combinations could be achieved for 3 switches, just turn the 4th switch. And then do the reverse of the steps that we taken for 3 switches. | In general if there are n switches, and you have turned the switches for (n - 1) switches, turn the nth switch. And then turn in reverse for the (n - 1) switches. Regards, David
The question could be re-worded: Can Peggy run through every possible combination of switch settings exactly once? Of course she can! How long that takes her and how well she can keep track of what she is doing are both practical issues, but certainly there is nothing preventing her from running through all the combinations to get the box open.
although the problem is unique in making us understand combinatorics, whats the problem exactly?
To put the specific solution into simple terms Peggy could simply iterate what she did for the first box (with 2 switches) on the top 2 switches of the second box for each similar step of the lower 2 switches. Thus taking 4 steps x 4 steps both being the same sequence she used for the first box.
Let 0 denotes switch off and 1 denotes switch on. There are 2 4 combinations of these 0 and 1. Let S be the set that denotes all possible sample points (i.e. S is the sample space). S = {{0,0,0,0},{1,0,0,0},{ 0,1,0,0},{1,1,0,0}, {0,0,1,0},{1,0,1,0},{0,1,1,0},{1,1,1,0},{0,0,0,1},{1,0,0,1},{0,1,0,1},{1,1,0,1},{0,0,1,1},{1,0,1,1},{0,1,1,1},{1,1,1,1}}.
The picture shows that the starting position is {0,0,0,0}. We need to show that there is a sequence with {0,0,0,0} as the starting point and it covers all 16 possible elements of S exactly once. Verify that one possible sequence is {0,0,0,0} - {1,0,0,0} - {1,1,0,0} - { 0,1,0,0} - {0,1,1,0} - {0,0,1,0} - {1,0,1,0} - {1,1,1,0} - {1,1,1,1} - {0,1,1,1} - {0,0,1,1} - {1,0,1,1} - {1,0,0,1} - {1,1,0,1} - {0,1,0,1} - {0,0,0,1}
This problem can be solved using {0,0,0,0} as the starting point and use a computer program to write all possible sequences that cover all 16 elements. Then do math to find absolute difference of the next sequence with the previous sequence. For example, absolute|{1,0,0,0} minus {0,0,0,0}| will give one as the answer. As long as there is a sequence that always give one for the 15 absolute differences calculation, we have an answer. I have not computed how many answers are possible but it's not hard to write an algorithm to do so.
I just want to add to Arjen that this is not the only possible combination. There is many ways of changing one bit per step, i.e.: 0000, 0001, 0011, 0010, 0110, 0100, 0101, 0111, 1111, 1110, 1100, 1101, 1001, 1000, 1010, 1011, as another possibility.
0000
1000
1100
0100
0110
0010
0011
0001
0101
1101
1001
1011
1010
1110
1111
0111
Problem Loading...
Note Loading...
Set Loading...
Number the dials arbitrarily from 0 to 3 . On the n th turn ( n = 1 , … 1 5 ), turn dial m , where 2 m is the greatest power of two that divides n . In other words, turn dials in this order: n m 1 0 2 1 3 0 4 2 5 0 6 1 7 0 8 3 9 0 1 0 1 1 1 0 1 2 2 1 3 0 1 4 1 1 5 0
This problem is equivalent to the search for a Gray code : a list of all 2 n different combinations of n bits, where each entry in the list differs from its neighbors by exactly one bit. The key fact is that Gray codes exist for all n ≥ 1 .
The search for a n -bit Gray code is equivalent to finding a Hamiltonian path (or loop) through a n -dimensional cube.
To generate a Gray code, start with A 0 = an arbitrary combination of n bits. To generate A n from A n − 1 , change the m th bit, where 2 m is the greatest power of two dividing n .
Thus,
n 0 1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 1 5 A n 0 0 0 0 0 0 0 1 0 0 1 1 0 0 1 0 0 1 1 0 0 1 1 1 0 1 0 1 0 1 0 0 1 1 0 0 1 1 0 1 1 1 1 1 1 1 1 0 1 0 1 0 1 0 1 1 1 0 0 1 1 0 0 0 change bit 0 change bit 1 change bit 0 change bit 2 change bit 0 etc.