Okay, you have N switches. They are all off. You may flip one switch at a time. You must visit each possible state of switches being flipped without repeating any state. At the end, you must be able to return to the original all-off state with one more flip. How many ways are there to do this? (Bonus: Ignoring the final rule that you must be able to return to the original state in one flip, how many additional ways are there to visit all states?)
Examples:
For 2 switches, this is trivial:
00
10 01
11
You can go around the circle in either direction, for a total of 2 possible paths. There is no way to ignore the final rule with 2 switches.
For 3 switches, there are more possibilities:
000 000 000 000 000 000
100 001 010 001 100 010 001 010 010 100 001 100
101 011 011 101 110 011 011 110 110 101 101 110
111 010 111 100 111 001 111 100 111 001 111 010
110 110 101 101 011 011
You can go around any circle in either direction, for a total of 12. Additionally, you can do any of the following:
000 001 011 010 110 100 101 111
000 001 101 100 110 010 011 111
000 010 011 001 101 100 110 111
000 010 110 100 101 001 011 111
000 100 101 001 011 010 110 111
000 100 110 010 011 001 101 111
These 6 paths will visit every possible state, but end on 111
, so they cannot be done in a cycle, since it will take 3 flips to get back to 000
.
It can be proven that there are no other paths which visit all states without repeats. Since there are 8 possible states, it will take 7 flips to get to them all, which is an odd number, so there must be an odd number of 1's at the end of the sequence. These 6 circles and 6 straight sequences have exhausted all possible paths that do not repeat.
The question is: How many such cycles exist for N switches? I found these by hand, but there must be some formula that would account for all possibilities in a less tedious manner. (And does this sequence exist in the OEIS? It probably should.)