26
1
Here is an ASCII-art of a 4-way intersection:
| | |
| |
| | |
| |
| | |
-----+-----+-----
| |
- - -| |- - -
| |
-----+-----+-----
| | |
| |
| | |
| |
| | |
(Note how the horizontal roads are 3 rows tall, while the vertical roads are 5 columns wide. This is for aesthetic reasons, because of the rectangular font.)
Your challenge is to produce this ASCII art. However, as I'm sure you all know, not every intersection has a road travelling off in every single direction. This particular intersection goes NESW
, but some intersections might go, for example, NW
:
| | |
| |
| | |
| |
| | |
-----+-----+
| |
- - -| |
| |
-----+-----+
Or it might go SWE
:
-----+-----+-----
| |
- - -| |- - -
| |
-----+-----+-----
| | |
| |
| | |
| |
| | |
Or it may even go E
, just a single direction (although you can hardly call this an intersection, but try to avoid being overly pedantic):
+-----+-----
| |
| |- - -
| |
+-----+-----
You need to write a program or function that can easily generate any of these combinations. More specifically, your challenge is to write a program or function that takes a string of directions, consisting of NESW
, as input, and outputs or returns this ASCII art of an intersection with roads pointing in those directions. These directions may appear in any order, but the input will not contain any characters except for N
, E
, S
, or W
. If you like, you may request inputs to be lowercase instead, but you must specify this in your answer. You may also assume that all inputs will contain at least one direction.
The last example had leading spaces on each line, because there is no road going west. If you do not have a road going west, these leading spaces are optional. This:
+-----+-----
| |
| |- - -
| |
+-----+-----
Would also be an acceptable output. Similarly, if N
or S
is gone, empty lines in there place are optional. One trailing newline is allowed, and trailing spaces are allowed as long as the output is visually the same.
You may take input and output in any reasonable format, such as STDIN/STDOUT, command line args, files, function arguments/return values, etc.
As usual, this is code-golf, so try to get the shortest possible answer in whatever language you happen to use!
Sample IO:
NESW:
| | |
| |
| | |
| |
| | |
-----+-----+-----
| |
- - -| |- - -
| |
-----+-----+-----
| | |
| |
| | |
| |
| | |
NS:
| | |
| |
| | |
| |
| | |
+-----+
| |
| |
| |
+-----+
| | |
| |
| | |
| |
| | |
S:
+-----+
| |
| |
| |
+-----+
| | |
| |
| | |
| |
| | |
EW:
-----+-----+-----
| |
- - -| |- - -
| |
-----+-----+-----
SE:
+-----+-----
| |
| |- - -
| |
+-----+-----
| | |
| |
| | |
| |
| | |
Are trailing spaces also allowed (if there's no
E
, for instance)? Are leading and trailing blank lines allowed if there's noN
orS
? – Greg Martin – 2016-09-06T17:42:25.380@GregMartin Yes, those are allowed. See my edit. – James – 2016-09-06T17:46:17.673
vaguely related, you reminded me of this code I mostly wrote, for road intersections in a roguelike game: https://github.com/CleverRaven/Cataclysm-DDA/blob/master/src/mapgen_functions.cpp#L1080-L1347
– Sparr – 2016-09-06T22:58:13.257