look! It's an ASCII maze! Soo coolzors, amazeballs and stuff.
+-+-----+---+
| | | |
| | ++ | |
| | ++ +-+ |
| | |
+-------+ | |
| | |
+---------+-+
But, but, but... it's a pain to work out which direction all the parts of the maze are going. I just want to draw the layout and the maze make itself sooper kul without loads of time.
What if I could just draw this in...
#############
# # # #
# # ## # #
# # ## ### #
# # #
######### # #
# # #
#############
That would be soo sweet!
The rules (Because rules is cools):
- Write code to convert a string into an ascii maze and output the result.
- Any non-whitespace character will be read as a wall.
- Each char of wall will decide which character to be based on it's neighbours (only in North, South, East and West directions).
- If a char has no non-whitespace neighbours, it will be a plus sign (+).
- If a char has neighbours in both vertical (North-South) and horizontal (East-West) directions, it will be a plus sign (+).
- If a char has neighbours only in a vertical (North-South) direction, it will be a pipe symbol (|).
- If a char has neighbours only in a horizontal (East-West) direction, it will be a minus sign (-).
- The Input can be a single string (with lines separated by newline characters, or an array of strings).
- All input characters will be printable ASCII characters, you don't need to deal with extended charsets.
- Use any old language you please.
- If there is white space before a line, it should be the same amount on each line. Any white space after each line of output is fine.
- Attempt to solve it with the smallest number of bytes.
Test cases:
1: Frame
Input:
##########
# #
# #
# #
##########
Output:
+--------+
| |
| |
| |
+--------+
2: Classic maze
Input:
#################
# #
# ##### # ##### #
# # # # # #
# # # # ##### # #
# # # # #
### # ####### # #
# # # # # #
# ### # ## # ##
# # ## #
#################
Output:
--------+-------+
| |
| --+-+ | ----+ |
| | | | | |
| + | | +---- | |
| | | | |
+-- | +----+- | |
| | | | | |
| --+ | ++ | -+
| | ++ |
+-----+-++----+--
3: Green eggs, man.
Input:
I do not like green eggs and ham.
I do not like them, sam I am.
Would you like them here or there?
I would not like them anywhere!
Output:
| ++ +++ ++++ +++++ +++- -++ ----
| ++ +++ ++++ +++++ +++ + +++
+-+++ +++ ++++ ++++ ++++ ++ +++---
| +++-+ +++ ++++ ++-+ +++++++++
4: Icicles
Input:
Word Icicle!
Word Icicle
Word cicle
ord cicle
ord icle
ord i le
or i le
or i l
or l
or
r
Output:
++++ ++++++-
++++ ++++++
++++ +++++
+++ +++++
+++ ++++
+++ | ++
++ | ++
++ | |
++ |
++
|
---
? \$\endgroup\$-
s at all or why classic maze doesn't have four+
s on the bottom row. \$\endgroup\$smallest number of characters
, not bytes? \$\endgroup\$+
in the middle of the 1st row 2) the!
of Icicles should be replaced with a-
. Could you please double-check these ones? \$\endgroup\$whitespace
, do you just mean just space? I don't want to have to support tabs and you probably don't want me to transform newlines either \$\endgroup\$