In the United States, the two opposing directions of traffic on a road are separated by a dashed yellow line if passing is allowed and two solid yellow lines if passing is not allowed.
(Just one side can be dashed to allow passing on that side, and yellow lines can mean other things like center or reversible lanes, but we aren't concerned with any of those cases.)
Write a program that takes in a run-length encoded string of P
for passing and N
for no passing, and prints an ASCII version of the corresponding road. Except for the center line, the road always has the same pattern, which can be easily inferred from the examples below.
There will be a positive decimal number before each P
and N
in the input string. This number defines the length of the passing or no passing region of the current part of the road.
Examples
An input of 12N
would produce 12 columns of no passing road (center line all =
):
____________
============
____________
An input of 12P
would produce 12 columns of passing road (center line -
repeating):
____________
- - - - - -
____________
Passing and no passing can then be combined, e.g. 4N4P9N7P1N1P2N2P
would produce:
______________________________
====- - =========- - - -=-==-
______________________________
These are 4 no passing columns, then 4 passing, then 9 no passing, etc.
Note that a passing zone always starts with a dash (-
) on the leftmost side, not a space (
). This is required.
Details
- The input will never have two
N
zones or twoP
zones in a row. e.g.4P5P
will never occur. - You don't need to support letters without a leading positive number. Plain
P
will always be1P
, plainN
will always be1N
. - There may be trailing spaces as long as they do not extend beyond the final column of the road. There may be one optional trailing newline.
- Instead of a program, you may write a function that takes in the run-length encoded string and prints or returns the ASCII road.
- Takes input in any standard way (stdin, command line, function arg).
The shortest code in bytes wins. Tiebreaker is earlier post.