This is a rock:
*
Rocks can be stacked. Apart from the bottom-most layer, each rock must rest on two other rocks, like this:
*
* *
You have a pile of rocks, and your boss wants you to pile them symmetrically, taking up the least horizontal space possible.
Your challenge is to take a number of rocks as input, and output that many rocks stacked symmetrically, on as small a base as possible.
For example, with input 4
:
You can't fit a pile of 4 rocks on a base of 2. With a base of 3, you can, but you can't make it symmetrical - you end up with something like
*
* * *
So you need a base size of 4, which uses up all your rocks, so the result is:
* * * *
Any trailing or leading whitespace is allowed in the output, and you may use any two distinct characters instead of *
and
. If there are multiple ways to stack the inputted number of rocks symmetrically with the same base, any of them are valid.
Scoring
This is code-golf, shortest wins!
Testcases
4 =>
* * * *
7 =>
* * *
* * * *
8 =>
*
* *
* * * * *
9 =>
* *
* * *
* * * *
12 =>
* * *
* * * *
* * * * *
13 =>
* *
* * * * *
* * * * * *
or
* *
* * * * *
* * * * * *
17 =>
* *
* * * *
* * * * *
* * * * * *
19 =>
* *
* * * *
* * * * * *
* * * * * * *
Or
*
* *
* * *
* * * * * *
* * * * * * *
20 =>
* *
* * *
* * * *
* * * * *
* * * * * *
56 =>
* * * * *
* * * * * *
* * * * * * *
* * * * * * * *
* * * * * * * * *
* * * * * * * * * *
* * * * * * * * * * *
or
* *
* * *
* * * * * *
* * * * * * *
* * * * * * * *
* * * * * * * * *
* * * * * * * * * *
* * * * * * * * * * *