In this challenge you will take a an ascii art image of a highway like so
| | | | | |
| | | |
| | | | | |
| | | |
| | | | | |
| | | |
| | | | | |
And you need to put rain across its lanes like so
|\\\|\\\| |\\|\\|
|\\\\\\\| |\\\\\|
|\\\|\\\| |\\|\\|
|\\\\\\\| |\\\\\|
|\\\|\\\| |\\|\\|
|\\\\\\\| |\\\\\|
|\\\|\\\| |\\|\\|
A highway will be defined as an ascii art string containing only the characters |
, and newlines. All rows of the image will have exactly the same number of characters. Every column will be one of the following
Empty space, all spaces
A line, all
|
A lane divider, alternating
|
and space
Furthermore there will always be a line before and after every lane divider. So
| | | | |
| | |
| | | | |
would be valid but
| | |
| | |
| | |
would not be since there is no line after the last lane divider.
And a lane divider will never be exactly next to a line. So
|| |
| |
|| |
Is invalid but
| || ||
| | ||
| || ||
| | ||
| || ||
is fine.
Additionally a highway must be at least two rows high and one column wide.
Task
Your job is to write a program or function that takes a valid highway (as a string or list of lines) as input and outputs the highway with rain across its lanes.
To put rain across a highway's lanes you must replace all space characters that appear between two consecutive lines, where those lines have at least one lane divider between them, with \
s. And leave all other characters the same.
So in the following diagram:
A B C 1 2 D
| | | | |
| | | | |
| | | | |
| | | | |
No rain should be put between A
and B
or B
and C
since there are no lane dividers between them, but rain should be put between C
and D
since lane dividers 1
and 2
are between them.
You may output an additional trailing newline, or add/remove trailing spaces from all lines equally if you wish.
This is code-golf so answers will be scored in bytes with fewer bytes being better.
Test cases
Simple case
| | | | | |
| | | |
| | | | | |
| | | |
| | | | | |
| | | |
| | | | | |
|\\\|\\\| |\\|\\|
|\\\\\\\| |\\\\\|
|\\\|\\\| |\\|\\|
|\\\\\\\| |\\\\\|
|\\\|\\\| |\\|\\|
|\\\\\\\| |\\\\\|
|\\\|\\\| |\\|\\|
Extra line
| | | | |
| | |
| | | | |
|\\\\|\\\|\| |
|\\\\\\\\\\| |
|\\\\|\\\|\| |
Unsynced lane dividers
| | |
| | |
| | |
| | |
| | |
|\\\\|\\\\\\|
|\\\\\\\\|\\|
|\\\\|\\\\\\|
|\\\\\\\\|\\|
|\\\\|\\\\\\|
Empty road
| | | | |
| | | | |
| | | | |
| | | | |
| | |\\\\\\\|\\|
| | |\\\|\\\\\\|
| | |\\\\\\\|\\|
| | |\\\|\\\\\\|
False roads (suggested by Arnauld)
| | | | |
| | | |
| | | | |
| | | |
| |\|\| |
| |\\\| |
| |\|\| |
| |\\\| |
Hard lane divider
| | | | |
| | |
| | | | |
| | |
|\\|\\|\\|\\|
|\\\\\|\\\\\|
|\\|\\|\\|\\|
|\\\\\|\\\\\|
Adjacent lane dividers
| || ||
| | ||
| || ||
| | ||
| || ||
|\\\||\\||
|\\\\\|\||
|\\\||\\||
|\\\\\|\||
|\\\||\\||
No lanes
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
One line
|
|
|
|
|
|
No lines