Challenge
We all know about normal Christmas trees - but how about an upside-down Christmas tree! This is a fairly easy, Christmas themed challenge. The objective of this challenge is to make me an ASCII upside-down Christmas tree. Here are the rules for this challenge:
- Accept an odd, positive integer. You can assume it will always be between
7
and51
. The base of the tree will be made of the characters:
___ \ / |
The top of the tree (the star), will be made up of a single
*
.Each line of the tree will be constructed using the format
<?>
where?
is any number of-
s. For example, if making a line of length5
, the line should be<--->
. Or if making a line of length8
, the line should be<------>
.Here is how the body of the tree should be constructed:
Take the odd number
n
given as input, and create a line of the tree that length.Subtract
4
fromn
and create a line of the tree that length.Subtract
2
fromn
and create a line of the tree that length.Decrement
n
by2
. After that, unlessn
equals5
, go back to step 2.
The base (see step 2.) the star (see step 3.) and each line of the tree (see steps 4. and 5.) should all be centered using the original odd number input (see step 1.) as the maximum width.
Examples/Test Cases
odd number inputed: 7
___
\ /
|
<-----> line length -> 7
<-> line length -> 7 - 4 = 3
<---> line length -> 7 - 2 = 5
*
odd number inputed: 13
___
\ /
|
<-----------> line length -> 13
<-------> line length -> 13 - 4 = 9
<---------> line length -> 13 - 2 = 11
<-----> line length -> 11 - 4 = 7
<-------> line length -> 11 - 2 = 9
<---> line length -> 9 - 4 = 5
<-----> line length -> 9 - 2 = 7
<-> line length -> 7 - 4 = 3
<---> line length -> 7 - 2 = 5
*
odd number inputed: 9
___
\ /
|
<-------> line length -> 9
<---> line length -> 9 - 4 = 5
<-----> line length -> 9 - 2 = 7
<-> line length -> 7 - 4 = 3
<---> line length -> 7 - 2 = 5
*
odd number inputed: 17
___
\ /
|
<---------------> line length -> 17
<-----------> line length -> 17 - 4 = 13
<-------------> line length -> 17 - 2 = 15
<---------> line length -> 15 - 4 = 11
<-----------> line length -> 15 - 2 = 13
<-------> line length -> 13 - 4 = 9
<---------> line length -> 13 - 2 = 11
<-----> line length -> 11 - 4 = 7
<-------> line length -> 11 - 2 = 9
<---> line length -> 9 - 4 = 5
<-----> line length -> 9 - 2 = 7
<-> line length -> 7 - 4 = 3
<---> line length -> 7 - 2 = 5
*
Rules
- Standard loopholes apply.
- This is code-golf, so the shortest answer in bytes wins!
repeat the above steps until the odd number minus 2 equals 5
- in the first input, the odd number is 7, and 7-2=5, therefore the tree should end instantly (I know what you mean, but it needs rephrasing) \$\endgroup\$7
, the minimum input, you would first create the three tree lines (sub-steps .1.1, .1.2, .1.3), then subtract2
from the odd number and test if it equals5
. The instruction to check if the "odd number minus 2 equals 5" is at the end, the other three steps should be performed first. But to answer your first comment, that would be fine. \$\endgroup\$7
as input or if you can accept4
, as in the fourth odd number (or3
if it’s 0-indexed). \$\endgroup\$