29
4
Write a program or function that draws a tree of trees, thus constructing a forest.
The trees are drawn like stacking a pyramid. The first (top) row contains 1
tree, the next row down contains 2
(for a total of 3
), the next contains 3
(for a total of 6
), and so on. If there aren't enough trees to complete a full row, fill it to the left and leave the spots on the right empty. Additionally, lower-level trees slightly overlap upper-level trees due to their placement.
This is a forest of size 1
/\
//\\
///\\\
||
||
This is a forest of size 2
/\
//\\
/\///\\\
//\\ ||
///\\\||
||
||
This is a forest of size 3
/\
//\\
/\///\\\/\
//\\ || //\\
///\\\||///\\\
|| ||
|| ||
This is a forest of size 4
/\
//\\
/\///\\\/\
//\\ || //\\
/\///\\\||///\\\
//\\ || ||
///\\\|| ||
||
||
This is a forest of size 5
(note the top of the fifth tree is covering the trunk of the first tree)
/\
//\\
/\///\\\/\
//\\ || //\\
/\///\\\/\///\\\
//\\ || //\\ ||
///\\\||///\\\||
|| ||
|| ||
(skip a few)
This is a forest of size 8
(extending the pattern)
/\
//\\
/\///\\\/\
//\\ || //\\
/\///\\\/\///\\\/\
//\\ || //\\ || //\\
/\///\\\/\///\\\||///\\\
//\\ || //\\ || ||
///\\\||///\\\|| ||
|| ||
|| ||
and so on.
Input
A single positive integer in any convenient format, n > 0
.
Output
An ASCII-art representation of the forest, following the above rules. Leading/trailing newlines or other whitespace are optional, provided that the trees all line up appropriately.
Rules
- Either a full program or a function are acceptable. If a function, you can return the output rather than printing it.
- Standard loopholes are forbidden.
- This is code-golf so all usual golfing rules apply, and the shortest code (in bytes) wins.
I'm not sure what the pattern is regarding the order in which the trees are drawn. That is, given
n
, what are the positions of the trees? – Luis Mendo – 2017-02-10T21:29:47.413@LuisMendo As I understand, they are filled in reading order. So, each row is filled in turn, and if there's not enough trees for the whole row, the remainder are placed as far left as possible in that row. – xnor – 2017-02-10T21:34:37.140
@LuisMendo xnor has it right. If I can re-word that to make it more clear, please ping me in chat. – AdmBorkBork – 2017-02-10T21:35:07.840
@xnor Thanks, it's totally clear to me now – Luis Mendo – 2017-02-10T21:59:46.547
@Adm Actually it was written right there in the challenge. Apparently I can't read :-) – Luis Mendo – 2017-02-10T22:01:14.783