Given an input of a list of blocks to drop at certain points, output the height of the resulting "tower."
The best way to explain this challenge is by example. The input will be a list
of 2n integers representing n blocks. The first integer is the block's x
position, 0-indexed, and the second is how wide the block is. For example, an
input of 2 4
represents the block (with x coordinates labeled below):
####
0123456789
Now, let's say the input is 2 4 4 6
. That is, one block at x=2 with a width
of 4, and one at x=4 with a width of 6:
######
####
Note that a.) blocks always "drop" from the very top of the tower and b.)
blocks will never "fall over" (i.e. they will always balance). So, an input of
2 4 4 6 12 1
represents:
######
#### #
Note that the final block has fallen all the way to the "ground."
Your final output should be the maximum height of the tower at each x-value up
to the largest. Hence, the input 2 4 4 6 12 1
should result in output
0011222222001
:
######
#### #
0011222222001
Input may be given as either a whitespace-/comma-separated string, an array of integers, or function/command line arguments. The block positions (x values) will always be integers 0 or greater, the width will always be an integer 1 or greater, and there will always be at least one block.
Output may be given as a single string separated by non-numerical characters
(ex. "0, 0, 1, ..."
), a single string listing all the digits (ex.
"001..."
—the maximum height is guaranteed to be 9 or less), or an array of
integers.
Since this is code-golf, the shortest code in bytes will win.
Test cases:
In Out
---------------------------------------------------------
2 4 4 6 12 1 0011222222001
0 5 9 1 6 4 2 5 1133333222
0 5 9 1 2 5 6 4 1122223333
0 5 2 5 6 4 9 1 1122223334
20 1 20 1 20 1 00000000000000000003
5 5 000011111
0 2 1 2 2 2 3 2 4 2 5 2 6 2 7 2 8 4 123456789999