Task
Your task is to draw these beautiful oak trees:
1 ->
@@@
@@@@@
@|.|@
_|_|_
2 ->
@@
@@@@@@
@@@@@@@@
@@| .|@@
| |
__|__|__
3 ->
@@@@@
@@@@@@@@@
@@@@@@@@@@@
@@@| |@@@
@| .|@
| |
___|___|___
4 ->
@@
@@@@@@@@
@@@@@@@@@@@@
@@@@@@@@@@@@@@
@@@@| |@@@@
@@| .|@@
| |
| |
____|____|____
5 ->
@@@@@
@@@@@@@@@@@
@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@
@@@@@| |@@@@@
@@@| .|@@@
| |
| |
| |
_____|_____|_____
6 ->
@@@@@@@@
@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@
@@@@@@| |@@@@@@
@@@@| |@@@@
@| .|@
| |
| |
| |
______|______|______
(that one sandbox commenter felt were similar to women with curly hair!)
The trees are allowed to be surrounded by any extra whitespace your solution creates as long as that doesn't break the tree, of course.
Algorithm
As per the examples above, we take n
to represent the width of the trunk and the specs of the tree will be given in terms of that.
Given n
:
- the height of the trunk is
n + 1
; - the width of the trunk in space characters is
n
; - the top row of the trunk is
n
times the character@
, followed by|
,n
times the space character, another vertical pipe
|
and thenn
times@
. - from the reference row up to the top of the crown, we only use
@
as follows:- there is one row with the same width as the reference row and each subsequent row above is shortened by one
@
than the previous shortening;
- there is one row with the same width as the reference row and each subsequent row above is shortened by one
- from the reference row downwards, we chop 2
@
from each side and then each row we go down, we chop one more@
than the previous row; - the last trunk row that is surrounded by a
@
has a.
immediately to the left of the right vertical pipe|
; - the bottom most row has the underscore
_
in all the tree width, except where the trunk vertical pipes|
are.
n
. If your language overflows at some point or you blow some recursion limit or wtv, that is fine. \$\endgroup\$