An H tree is a fractal tree structure that starts with a line. In each iteration, T branches are added to all endpoints. In this challenge, you have to create an ASCII representation of every second H tree level.
The first level simply contains three hyphen-minus characters:
The next levels are constructed recursively:
- Create a 2x2 matrix of copies from the previous level, separated by three spaces or lines.
- Connect the centers of the copies with ASCII art lines in the form of an H. Use
-for horizontal lines,
|for vertical lines, and
+whenever lines meet each other.
-+- -+- | | +-----+ | | -+- -+-
-+- -+- -+- -+- | | | | +--+--+ +--+--+ | | | | | | -+- | -+- -+- | -+- | | +-----------+ | | -+- | -+- -+- | -+- | | | | | | +--+--+ +--+--+ | | | | -+- -+- -+- -+-
- Input is an integer representing the level of the ASCII art H tree as described above (not the actual H tree level), either zero- or one-indexed.
- Output is flexible. For example, you can print the result or return a newline-separated string, a list of strings for each line, or a 2D array of characters.
- You must use
+and space characters.
- Trailing space and up to three trailing white-space lines are allowed.
This is code golf. The shortest answer in bytes wins.