22
1
Thanks to this question for some inspiration
In this challenge we will represent a line of dominoes as a string of |
, /
and \
. You will be given a string of dominoes as input and you must determine what they look like when they have settled. Here are the rules for how dominoes fall over
A standing domino,
|
, left of a left fallen domino,\
, will become a left fallen domino as well.A standing domino,
|
, right of a right fallen domino,/
, will become a right fallen domino as well.If a standing domino is between a left fallen
\
and a right fallen/
domino, it will remain standing.
These rules are applied repeatedly until the arrangement no longer changes.
Here is an example of how a single input might arrive at its conclusion
|||||||\/|||||||\||\|||/||||||\|||||
||||||\\//|||||\\|\\|||//||||\\|||||
|||||\\\///|||\\\\\\|||///||\\\|||||
||||\\\\////|\\\\\\\|||////\\\\|||||
|||\\\\\////|\\\\\\\|||////\\\\|||||
||\\\\\\////|\\\\\\\|||////\\\\|||||
|\\\\\\\////|\\\\\\\|||////\\\\|||||
\\\\\\\\////|\\\\\\\|||////\\\\|||||
Your task is to write code that finds and outputs the end result of a input. You may assume that the input is always valid and contains at least 2 characters.
This is code-golf so answers will be scored in bytes with fewer bytes being better.
Test cases
|||/|||| -> |||/////
|||\|||| -> \\\\||||
|/||||\| -> |///\\\|
||/|||\| -> ||//|\\|
||\|||/| -> \\\|||//
6Backslash escaping ahoy! (May we use other symbols?) – Arnauld – 2018-01-05T15:53:29.377
1@Arnauld No you should use the slashes. – Post Rock Garf Hunter – 2018-01-05T15:54:12.867
1I can't... figure out what to escape and what to not. – totallyhuman – 2018-01-05T16:08:02.650
Will the input ever be the empty string or a single character? – Doorknob – 2018-01-05T16:08:50.563
What happens in case of
/\
? – Erik the Outgolfer – 2018-01-05T16:09:52.290@EriktheOutgolfer Nothing. Anything the rules don't tell us to change remains the same. – Post Rock Garf Hunter – 2018-01-05T16:12:12.033
@Doorknob No you may assume at least 2 characters. Adding to the question shortly. – Post Rock Garf Hunter – 2018-01-05T16:12:35.910
3It bothers me more than it should that things like `////////|\ are considered stable. – MooseBoys – 2018-01-05T22:12:16.130