Inspired by this challenge.
Given a pre-configured switchboard and a list of indexes, invert the switches at the given indexes.
A switchboard is made up of some number of switches (
^) wrapped in
-'s and arranged into rows of varying length. Here is an example switchboard:
-v-^-v- -^-v- -v-^-v-
To invert/flip a switch means changing it from
^, or from
The switches are indexed left-to-right, top-to-bottom. E.g., in the example above, the last
v in the first row would be in position 3 and the
^ in the middle row would be at 4 (using 1-indexing).
- A string (or list of strings) representing the switchboard. It is guaranteed to match the regex
- A possibly empty list of numbers representing indexes, may be 0 or 1 (or some arbitrary number if you want) indexed. These are the switches that need to be flipped.
- A switchboard in the same shape as the input with the specified switches inverted. Any unspecified switches should retain their initial state.
- Input will always be correctly formatted and no given indexes will be out of bounds.
- The list of indexes will be sorted and will have no duplicates.
- State in your answer what indexing you use, be it 0, 1, or some arbitrary one.
- Trailing whitespace is fine as long as the output looks like the input.
- This is code-golf so shortest code wins.
#Using 1-indexing input: #Empty Case , -v-^-v- output: -v-^-v- input: #Single switch , -v- output: -^- input: #Skip a line [3,5], -^-v-v- -v- -^-^- output: -^-v-^- -v- -v-^- input: #Flip one in each line + number wrap [3,4,6], -^-v-v- -v- -^-^- output: -^-v-^- -^- -^-v- input: #Flip 'em all [1,2,3,4,5,6], -^-v-v- -v- -^-^- output: -v-^-^- -^- -v-v-