前几天,我儿子让我用乐高积木为他建造一个楼梯。我想到了这样的事情:
然后我的孩子问我一个程序,该程序使用最少的字节数在计算机屏幕上生成了类似的阶梯。我不太擅长于代码高尔夫,所以我需要您的帮助。我需要一个程序:
- 接收带有楼梯所需的级别数的正整数。
- 输出带有您在图像中看到的图案的楼梯图。
输出将为文本格式,但可以将积木区分开。例如,您可以将'█'字符用作半个字块,并以所需的任何颜色对其进行绘制,或者仅选择您选择的任何字符。
限制条件:
- 块需要具有三种不同的颜色,并且将使用尽可能长的颜色(如果输入为1或2,则没有足够的块来使用所有三种颜色)。如果需要,可以使用'░▒░'字符,例如,也可以选择三个不同的字符。
- 同一行中不能有两个相同颜色或图案的块并排放置。
只要画上楼梯,我儿子就不会真正在意尾随空间或换行。
示例(对字符的错误选择表示抱歉):
Input: 1
Output:
██
Input: 2
Output:
██
▓▓
Input: 3
Output:
██
▓▓
██░░
Input: 5
Output:
██
██
██░░
██░░
██░░▓▓
17
告诉你的孩子,有趣的是自己构建/编程:-)
—
Luis Mendo
欢迎光临本站!通常不希望将ASCII艺术和图形输出结合起来,因为这会带来两个并行的挑战。另外,如果您选择ASCII,我会允许使用实际的ASCII字符(我想您已经这样做了,但也许更明确了),因为某些语言可能会遇到非ASCII字符的问题
—
Luis Mendo
仅供参考,这些街区称为Duplo
—
caird coinheringaahing
@cairdcoinheringaahing duplo没有圆形按钮。
—
Christoph