I have a crank-operated music box that can play a series of four notes. When I turn the crank, it plucks one of four strings, depending on the position of the crank and the direction of the turn. When the crank is turned due north, the box (with its strings numbered 1 through 4) looks like this:
1 | 2 | O 4 3
From there, I can turn the crank clockwise to pluck the #2 string and point the crank east:
1 2 O--- 4 3
Alternatively, I could have also turned the crank counterclockwise from north to play the #1 string and end with a crank pointing west:
1 2 ---O 4 3
At any given time, then, the box can play one of two notes: the next note available in the clockwise direction or the next note in the counterclockwise direction.
Your challenge is to write a program or function that accepts a non-empty string of note values (i.e., numerals
4) and determine if it is ever possible to play that sequence of notes on the music box. Produce a truthy or falsy result to indicate the playability or non-playability of the input.
The input makes no assumptions about initial start position. The inputs
214(starting east and moving strictly counterclockwise) and
234(starting north and moving strictly clockwise) and both valid.
The crank may move freely in either direction after each note. A series of the same note is possible (e.g.,
33333) by moving back and forth across one string. The series
1221441is perfectly playable (starting west, moving clockwise two steps, then counterclockwise three steps, then clockwise two steps).
1 1234 1221 3333 143332 22234 2234 22214 1221441 41233
13 (note 3 is never available after note 1) 1224 (after `122`, the crank must be north, so 4 is not playable) 121 (after `12` the crank is east; 1 is not playable) 12221 (as above, after `1222` the crank is east) 43221