My wife is very, let's say, particular when it comes to putting ornaments on our Christmas tree. Let's get her some code to help her in this trying time.
Input
Given an input 2 < n < 10
the height of the tree and 0 < k < n
the distinct number of ornaments.
Task
Decorate the tree starting with 1
and increment to k
as we wrap the ornaments around the tree. If we reach k
and we have more branches to decorate then start back at 1
.
It is okay if there are not the same number of each ornament on the tree, as long as the pattern is satisfied.
The ornaments should appear above each branch ^
except for the top row.
The tree is structured by starting with one branch then the next level has + 1 branches with a space between each, staggered from the top like:
^
^ ^
For a third row you would add one more branch and stagger them again such that no branch is on the same column (if you think of it like a grid).
^
^ ^
^ ^ ^
Output
Output your decorated tree.
Examples
1.
n = 3, k = 2
^ //Height is 3
^ ^
^ ^ ^
Now we decorate each branch starting with 1 and increment to k:
^
1 2
^ ^
1 2 1
^ ^ ^
2.
n = 6, k = 5
^ //Non-Decorated
^ ^
^ ^ ^
^ ^ ^ ^
^ ^ ^ ^ ^
^ ^ ^ ^ ^ ^
^ //Decorated
1 2
^ ^
3 4 5
^ ^ ^
1 2 3 4
^ ^ ^ ^
5 1 2 3 4
^ ^ ^ ^ ^
5 1 2 3 4 5
^ ^ ^ ^ ^ ^
3.
n = 5, k = 1
^
^ ^
^ ^ ^
^ ^ ^ ^
^ ^ ^ ^ ^
^
1 1
^ ^
1 1 1
^ ^ ^
1 1 1 1
^ ^ ^ ^
1 1 1 1 1
^ ^ ^ ^ ^
This is code-golf so the shortest code wins! Have fun and good luck!