You will be given a positive integer
n as input. Output should be a pyramid-like sandpile built on the rules specified below:
- Each integer "falls" downward from the same initial starting point, like sand falling into a conal-shape.
- Numbers greater than the number directly below it when it hits the sandpile will fall to the right, if able.
- Numbers less than the number directly below it when it hits the sandpile will fall to the left, if able.
- Numbers equal to the number directly below it when it hits the sandpile will stay in place.
- Numbers are able to fall to the left/right if they can move down and to the left/right respectively. That is, if there is already a number below and to the left/right, depending on the direction, the currently falling number does not move.
- A number will continue to tumble down the sandpile until it cannot be moved into its next position, or hits the floor.
The initial comparison check only applies to the first encountered integer, not for each successive encounter as it tumbles down the sandpile.
Trailing spaces are okay but trailing new lines are not.
No leading spaces or new lines except where needed to preserve the structure of the sandpile.
You may write a full program or function.
You may assume input will only contain some combination
2 2 2 135 1345 13445
4 4 4 135 1235 12235
3 3 3 3 34 355 3644 239475 201277445 020373685575