ASCII boxes look like this:
++ +---+ +------+ +---+ +---+
++ | | | | | | | |
| | | | | | | |
+-+ | | | | | | | |
+-+ | | | | | | +---+
+---+ | | | |
+--+ | | | | ++
| | | | | | ||
| | +------+ | | ||
+--+ | | ||
+---+ ||
||
+-----+ ||
+------------+ | | ++
| | | |
| | | |
+------------+ +-----+
Here are some examples of the same ASCII boxes, imploded:
++ +- -+ +- -+ +- -+ +- -+
++ | - | | - - | | - | | - |
| | | -- | | | | |
+-+ | | | | " | - |
+-+ | - | || | | +- -+
+- -+ | | | |
+--+ | -- | | | ++
| | | - - | " ||
| | +- -+ | | ||
+--+ | - | | |
+- -+ | |
-- ||
- - +- -+ ||
+- - - -+ | - - | ++
| -- -- | | = |
| -- -- | | - - |
+- - - -+ +- -+
- -
--
Here is a link to all of these test case boxes in an easier-to-copy format. The order is all inputs followed by all outputs in the same order.
Your goal is to take an ASCII box as input, and return the imploded box. The rules of implosion are:
- "+" never changes; neither do "-" or "|" directly adjacent to "+"
- Starting from the corners, the "-" and "|" move inward by one space more than the same character closer to the corner did. If a "-" and "|" would ever move to the same spot, neither moves.
- If a "-" and "-" move to the same spot, put a "=" in that spot. If a "|" and "|" move to the same spot, put a " in that spot. These count as two of their respective characters in the same spot moving in opposite directions.
- Two "-" or two "|" can move past each other, as seen in the bottom left example.
- If the box is skinny enough, it will start expanding outwards in the same way, always moving away from the side it started out part of.
- The result should be symmetric across the center line in both the x and y directions (ignoring newlines); this includes spaces, so the result may need to be padded with spaces to satisfy that.
Rule Details:
- This is code-golf, so shortest program in bytes wins.
- Standard loopholes apply.
- You can assume each line ends in a newline character.
- The only characters in the input string will be "+", "-", "|", " ", and "\n" (newline), and your output string should follow the same rules, with the addition of "=" and " as possible characters.
- You may optionally have a single trailing newline at the end of the last line.
- The smallest ASCII box you need to handle is the top-left example. Every ASCII box will have exactly 4 "+"s, exactly at its corners.
- You will need to handle boxes of size
m x n
for any integersm,n
such that2<=m,n<256
(largest possible string size of255*(255+1)
) - You can assume you will always get a single valid ASCII box as input.
||
in that example need to be a"
or something... \$\endgroup\$"
though? I guess the"
only appears on 3-wide or greater? \$\endgroup\$"
go? On the left, or on the right side? It can't be both, but it can't be either because the result is symmetrical. \$\endgroup\$