挑战
给定一个可打印的ascii字符的矩形网格作为字符串或通过标准输入,编写一个将非空格字符折叠为底部的函数或程序。
规则:
- 输出具有与输入相同的尺寸和字符。
- 在非空格字符
(row a,column b)
不能有空格字符' '
的(a-1, b)
,(a-1,b-1)
或者(a-1,b+1)
,当行从最底层向上编号。结果是所有垂直桩都应向侧面倒塌。 - 非空格字符可以在大多数
(initial height - final height)
位置向左或向右移动(见图1)。 - 您可以假定图片有足够的空间折叠而字符不会掉出屏幕。
图1:分别@#$
显示为的字符的最终位置x,y,z
。
..............
...@..........
..xxx.........
.xxxxx...#....
xxxxxxx.yyy.$.
字符折叠的顺序可以自由选择。尾随空格不行,但尾随换行符是可以的。
这是代码高尔夫球,因此最短答案以字节为单位!
例
(__)
(oo)
/------\/
/ | ||
* /\---/\
~~ ~~
..."Have you mooed today?"...
一种可能的输出:
--(_
/----|/|(o_)
/|/~\---~\\/o)
..."Have*you~mooed~today?"...
只是要澄清一下,字符掉落的方式可以是硬编码的,而不是每次都随机生成的?
—
ETHproductions 2016年
那头牛对你做了什么?:(
—
FlipTack
@ETHproductions是正确的。我的示例按照从下到上,从左到右的顺序执行,但是只要遵守规则,就可以采用随机顺序或其他方法。
—
2016年
@ Flp.Tkc这只是一个模型。
—
2016年
@DestructibleWatermelon如果某个角色碰巧掉出了屏幕,那是他们的错,而不是您的错。
—
2016年