25
3
Today's challenge is to draw a binary tree as beautiful ascii-art like this example:
/\
/ \
/ \
/ \
/ \
/ \
/ \
/ \
/ \
/ \
/ \
/ \
/ \
/ \
/ \
/ \
/\ /\
/ \ / \
/ \ / \
/ \ / \
/ \ / \
/ \ / \
/ \ / \
/ \ / \
/\ /\ /\ /\
/ \ / \ / \ / \
/ \ / \ / \ / \
/ \ / \ / \ / \
/\ /\ /\ /\ /\ /\ /\ /\
/ \ / \ / \ / \ / \ / \ / \ / \
/\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
You will be given a positive integer as input. This input is the height of the tree. The above example has a height of six.
You may submit either a full-program or a function, and you are free to use any of our default IO methods. For example, printing the tree, returning a string with newlines, returning a 2d char array, saving the tree to a file, etc. would all be allowed.
Trailing spaces on each line are permitted.
Here are some examples of inputs and their corresponding outputs:
1:
/\
2:
/\
/\/\
3:
/\
/ \
/\ /\
/\/\/\/\
4:
/\
/ \
/ \
/ \
/\ /\
/ \ / \
/\ /\ /\ /\
/\/\/\/\/\/\/\/\
5:
/\
/ \
/ \
/ \
/ \
/ \
/ \
/ \
/\ /\
/ \ / \
/ \ / \
/ \ / \
/\ /\ /\ /\
/ \ / \ / \ / \
/\ /\ /\ /\ /\ /\ /\ /\
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
Unfortunately, the output grows exponentially, so it's hard to show larger examples. Here is a link to the output for 8.
As usual, this is a code-golf challenge, so standard loopholes apply, and try to write the shortest program possible in whatever language you choose.
Happy golfing!
Can there be trailing spaces to make all line the same length? – xnor – 2017-01-06T06:23:56.420
@xnor Yes, that is fine. – James – 2017-01-06T06:25:22.733