In some nations there are recommendations or laws on how to form emergency corridors on streets that have multiple lanes per direction. (In the following we only consider the lanes going in the direction we are travelling.) These are the rules that hold in Germany:
- If there is only one lane, everyone should drive to the right such that the rescue vehicles can pass on the left.
- If there are two or more lanes, the cars on the left most lane should drive to the left, and everyone else should move to the right.
Challenge
Given the number N>0
of regular lanes, output the layout of the lanes when an emergency corridor is formed using a string of N+1
ASCII characters. You can use any two characters from ASCII code 33
up to 126
, one to denote the emergency corridor, and one for denoting the cars. Trailing or leading spaces, line breaks etc are allowed.
Examples
Here we are using E
for the emergency corridor, and C
for the cars.
N Output
1 EC
2 CEC
3 CECC
4 CECCC
5 CECCCC
6 CECCCCC
etc
C
andE
, but there are so many nice approaches possible for this challenge! Using mathematical operations forC=1
/E=2
orC=2
/E=3
like the top answer does; usingC=0
/E=1
with10^(n-1)
; usingC=0
/E=.
by decimal formatting0.0
; usingC=1
/E=-
by utilizing-1
; etc. etc. So many unique possibilities for a challenge that looked so to-the-point at first. Too bad I can only +1 once. ;) \$\endgroup\$