Given two parameters lane pattern and road length, print an ASCII representation of the lane markings for Roads and Traffic Service to paint the roads.
Example input/output
Input: BTHMLRPHU
, 21
I don't care if you take two parameters or concatenate the number onto the end of the string, it's unambiguous.
Input may be taken from STDIN, as a function argument, environment variables, whatever makes sense in your language.
Output:
! | x ## | | x x !
! B | /\ x HOV3 ## <- | -> | ^^ x HOV3 x !
! B | \/ x HOV3 ## | | | | ^^ x HOV3 x !
! | x ## | | x x !
! | x ## | | x x !
! | | ## | | | | !
! | | ## | | | | !
! | | ## | | | | !
! B | /\ | HOV3 ## <- | -> | ^^ | HOV3 | !
! B | \/ | HOV3 ## | | | | ^^ | HOV3 | !
! | x ## | | x x !
! B | /\ x HOV3 ## <- | -> | ^^ x HOV3 x !
! B | \/ x HOV3 ## | | | | ^^ x HOV3 x !
! | x ## | | x x !
! | x ## | | x x !
! | | ## | | | | !
! | | ## | | | | !
! | | ## | | | | !
! B | /\ | HOV3 ## <- | -> | ^^ | HOV3 | !
! B | \/ | HOV3 ## | | | | ^^ | HOV3 | !
! | x ## | | x x !
Each character denotes 0.5 metres in width and one kilometre in length.
Specification
Lane markings
For every 10 km stretch of road, markings are painted at kilometres 2, 3, 9 and 10 (from the "top" of the output). Markings are centred in the lane. With the exception of the bike lane and median, all lanes are 3 metres (6 characters) wide.
ASCII diamond and arrow characters are not permitted in lieu of the markings as indicated in the example output.
B
: Bike lane.B
marking. 1.5 metres (3 characters) wide.T
: Transit. Diamond markingH
: High-occupancy vehicle lane.HOV3
markingL
andR
: Turning lane. Arrow markingP
: Passing lane. Caret markingsU
: Unrestricted lane. No markings
Separators (in order of precedence)
- Median:
##
(denoted byM
in the input string, replaces any other separator including ditch) - Ditch (extreme left and extreme right):
!
Exclamation mark - HOV lanes alternate between
x
and|
every 5 km - Normal:
|
Constraints
Your function or program must:
- Print to STDOUT (this means equivalents of
System.out.print
for Java,console.log
for JavaScript, etc.) - Be able to print 1 - 9 lanes with 0 - 10 medians
- Be able to print up to 50 km of roadway (50 lines of output)
- Not use any standard loopholes
- Trailing white space is not acceptable with the exception of an optional
\n
at the end of the output
Largest possible output: 3700 bytes (74 characters * 50 lines).
Smallest possible output: 5 bytes (with input B
, 1)
Assumptions
- No adjacent medians (substring
MM
will not occur) - The second line of markings might be cut off (for example if the length is 9 or 12 km)
- Lanes may not logically make sense (any order is possible, for example a right turn lane on the left of the road)
This is code-golf, so shortest code (in bytes) wins!