Write a program or function that takes in a nonempty list of integers in any reasonable convenient format such as
4, 0, -1, -6, 2 or
[4 0 -1 -6 2].
Print or return a string that depicts the list as an ASCII art forest where each number becomes a tree of proportional height. Each tree takes up four columns of text in the output as follows:
A positive integer N becomes a tree whose base is
__|_and top is
^, with N layers of
/ \in between.
For example, when N = 1 the tree is
^ / \ __|_
when N = 2 the tree is
^ / \ / \ __|_
when N = 3 the tree is
^ / \ / \ / \ __|_
and so on.
A negative integer N becomes just like the corresponding positive tree except a vertical bar is between the branch slashes instead of a space.
For example, when N = -1 the tree is
^ /|\ __|_
when N = -2 the tree is
^ /|\ /|\ __|_
when N = -3 the tree is
^ /|\ /|\ /|\ __|_
and so on.
When the integer is 0 there is technically no tree, just an empty space of four underscores:
The underscores at the base of each tree must line up in the output, i.e. all the trees must have their bases at the same level. Also, a single underscore is added to the end of the line of underscores after the last tree. This makes it so every tree has an empty column of "air" on either side of it.
As an example, the output for
4 0 -1 -6 2 would be
^ /|\ ^ /|\ / \ /|\ / \ /|\ ^ / \ ^ /|\ / \ / \ /|\ /|\ / \ __|_______|___|___|__
Note how the tree patterns always have a leading column of empty space but an underscore had to be added to pad the right side of the last tree.
- Trailing spaces on any lines are fine, but there should be no unnecessary leading spaces.
- Leading newlines are not allowed (the tallest tree should touch the top of the output text grid) and only up to one trailing newline is allowed.
- The list may contain any integers from -250 to 250 inclusive. Handling taller trees is not required.
The shortest code in bytes wins.
^ / \ / \ / \ __|__
^ /|\ /|\ __|__
0, 1, 0:
^ / \ ______|______
0, -1, 2, -3, 4:
^ ^ / \ ^ /|\ / \ ^ / \ /|\ / \ /|\ / \ /|\ / \ ______|___|___|___|__