Every programmer knows that brackets []{}()<>
are really fun. To exacerbate this fun, groups of interwoven brackets can be transformed into cute and fuzzy diagrams.
Let's say that you have a string that contains balanced brackets, like [{][<(]})>(())
. Step one is to rotate the string 45 degrees clockwise. (In Mathematica, this can be almost done with Rotate[ur_string,-pi/4]
). Here is the result of the first step:
[
{
]
[
<
(
]
}
)
>
(
(
)
)
Next add a diagonal space between each character.
[
{
]
[
<
(
]
}
)
>
(
(
)
)
Next, start with the left-most bracket and draw a square between it and its partner in crime.
+---+
| |
| { |
| |
+---+
[
<
(
]
}
)
>
(
(
)
)
Repeat this process with each pair of brackets, overwriting previous characters with +
s if need be.
+---+
| |
| +-+---------+
| | | |
+-+-+ |
| |
| [ |
| |
| < |
| |
| ( |
| |
| ] |
| |
+-----------+
)
>
(
(
)
)
Continue until you have made everything nice and square.
+---+
| |
| +-+---------+
| | | |
+-+-+ |
| |
| +-----+ |
| | | |
| | +---+-+---+
| | | | | |
| | | +-+-+-+ |
| | | | | | | |
| +-+-+-+ | | |
| | | | | |
+-----+-+---+ | |
| | | |
| +-----+ |
| |
+---------+
+-----+
| |
| +-+ |
| | | |
| +-+ |
| |
+-----+
Input
Input will be a single line of balanced brackets and no other characters, with each bracket being one of []{}()<>
. Each type of bracket is balanced individually, though different types may overlap (this is what makes the squares look interesting). A trailing newline is optional.
Output
Output will be the interlocking square pattern generated from the bracket string. Trailing spaces and trailing newline are optional, but there mustn't be leading whitespace.
Goal
This is code-golf, fewest bytes wins.
[[]]
can we output two squares overlapping or do we have to output one square inside the other? \$\endgroup\$