The purpose of this challenge is to figure out whether all the dominoes will fall, given an input string representing a top view of the table.
The program can take the input as a single string with newlines or a list of strings. Spaces denote, well, empty spaces, and the rest represent dominoes.
The start domino and the direction the dominoes start to fall will be denoted by one of
v(down). There will be exactly one start domino in the input.
The other dominoes will be represented by one of the following four characters:
|- falls right when pushed from the left, falls left when pushed from the right
-- falls up when pushed from the bottom, falls down when pushed from above
/- falls right when pushed from the top and vice versa, falls left when pushed from the bottom and vice versa
\- falls left when pushed from the top and vice versa, falls right when pushed from the bottom and vice versa.
- keep the momentum going in the same direction, and the slashes (
\) cause quarter-turns.
Dominoes may not fall twice. If a domino falls, you may consider that an empty space in the next iteration.
A truthy/consistent value if all the dominoes will fall, and a consistent falsy value otherwise
Here's an example to make it a bit more clear (
o represents a fallen domino for the sake of this example):
Step 1 - Starts at the 4th domino in the first row \||< - - - \||\ Step 2 - start domino has fallen \||o - - - \||\ Step 3 - Go left because start was '<' \|oo - - - \||\ Step 4 - keep going left \ooo - - - \||\ Step 5 - keep going left \ooo - - - \||\ Step 6 - keep going to left, will go down next oooo - - - \||\ Step 7 - change direction, go down because of '\' oooo o - - \||\ Step 8 - keep going down oooo o o - \||\ Step 9 - go down, will go left next because of '\' oooo o o - o||\ Oops! Can't go any further, so output should be a falsy value
Just to clarify, there's no gravity or anything. The direction depends on the position of the domino (
This is code-golf, so shortest code in bytes wins.
More test cases:
> _________________________________________________________ \|||< - - /||| __________________________________________________________ \|/ /|/ - - \||\ ^
\|/ - - /|/| <-This last '|' doesn't fall, because the '/' before it has already fallen once ^ __________________________________________________________ |< | <- This last '|' doesn't fall, because the dominoes don't wrap around. __________________________________________________________ >||\|| Because after the '\', it tries to go up