The other day, our team went to an escape room. One of the puzzles involved a board of six mechanical switches where you had to find the correct combination of on and off in order to unlock a box, somewhat like this:
-v-v-v-
-v-v-v-
Being developers, we decided it would be more efficient to try every single one of 2^6=64 combinations than actually solve the puzzle. So we assigned some poor guy to do some binary counting:
-v-v-v-
-v-v-v-
-v-v-v-
-v-v-^-
-v-v-v-
-v-^-v-
-v-v-v-
-v-^-^-
and so on.
The challenge
Write a program that, given the switches all in off position as a string formatted as above, generates all combinations of on and off in any order.
You can write either a full program or a function. Thus, your program can either take in input through stdin, a file, or as a single string argument, and either return or print the output. If returned, the output may be in a list/array/etc. rather than a single string. If the output is a single string, the boards should be separated by newlines (trailing newlines are allowed.)
The input strings will match the regex r'((-v)+-)(\n(-v)+-)*'
and represent one board with all switches off. This means no zero case, and switches are left-aligned. Each row might not have the same number of switches.
Each output board should be of the exact same format as the input, except that the v's may be replaced by ^'s as required. The output boards can be separated by any number of newlines.
Since runtime is naturally O(2^n) in the number of switches, your code will not be tested on any more than 10 switches in any arrangement.
This is code-golf, so shortest code in number of bytes wins.
Sample inputs and outputs
Input:
-v-
Possible output:
-v-
-^-
Input:
-v-
-v-
Possible output:
-^-
-^-
-^-
-v-
-v-
-^-
-v-
-v-
Since it's extremely tedious to check your answer for bigger numbers of switches, here's a Python script as a sanity check tool. (I've included a currently commented-out snippet to generate expected output from a given input file in case you want more test cases.) It's quite a bit less flexible in terms of input and output than the spec, unfortunately; put the input string in a file named 'input' and the newline-separated output (sorry, no list formatting) in a file named 'output' in the same directory and run python3 sanitycheck.py
.