给定输入要在某些点放下的块的列表,请输出结果“塔”的高度。
解释此挑战的最佳方法是通过示例。输入将是2n个代表n个块的整数的列表。第一个整数是块的x位置(从0开始),第二个整数是块的宽度。例如,输入2 4
代表该块(下面标有x坐标):
####
0123456789
现在,假设输入为2 4 4 6
。也就是说,x = 2处的一个块的宽度为4,x = 4处的一个块的宽度为6:
######
####
请注意,a。)块始终从塔的顶部“掉落”,b。)块永远不会“掉落”(即,它们始终保持平衡)。因此,输入的
2 4 4 6 12 1
代表:
######
#### #
请注意,最后一块已经完全落到了“地面”上。
您的最终输出应该是每个x值处塔的最大高度,直至最大。因此,输入2 4 4 6 12 1
应产生输出
0011222222001
:
######
#### #
0011222222001
输入可以以空格/逗号分隔的字符串,整数数组或函数/命令行参数的形式给出。块位置(x值)将始终为0或更大的整数,宽度将始终为1或更大的整数,并且始终至少有一个块。
输出可以是由非数字字符(例如"0, 0, 1, ..."
)分隔的单个字符串,列出所有数字的单个字符串(例如
"001..."
-保证最大高度为9或更小)或整数数组。
由于这是code-golf,因此以字节为单位的最短代码将获胜。
测试用例:
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
我们可以将输入作为2元组的数组吗?
—
lirtosiast
@ThomasKwa不,输入必须是一维数组。
—
Doorknob