给定的整数Ñ ≥1,输出2D表示†宽度的百分比符号的Ñ。结构如下:
- 创建一个由零填充的n × n矩阵(或列表列表)。
- 在左上角和右下角插入一个。
- 将它们放在从左下角到右上角的对角线上。
对于输入n = 4,此构造如下所示:
1. 4x4 matrix of 0s
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
2. 1s in TL and BR corners
1 0 0 0
0 0 0 0
0 0 0 0
0 0 0 1
3. 1s across BL-TR diagonal
1 0 0 1
0 0 1 0
0 1 0 0
1 0 0 1
这是一个代码高尔夫球,因此以字节为单位的最短程序获胜。
†我使用1和0的矩阵,但是也可以使用任何非空白字符和空格的字符串。因此,上面的示例可能类似于:
# #
#
#
# #
要么
# #
#
#
# #
测试用例
n
output
1
1
2
1 1
1 1
3
1 0 1
0 1 0
1 0 1
4
1 0 0 1
0 0 1 0
0 1 0 0
1 0 0 1
10
1 0 0 0 0 0 0 0 0 1
0 0 0 0 0 0 0 0 1 0
0 0 0 0 0 0 0 1 0 0
0 0 0 0 0 0 1 0 0 0
0 0 0 0 0 1 0 0 0 0
0 0 0 0 1 0 0 0 0 0
0 0 0 1 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0 1
最后说明
添加一个解释将不胜感激。
'1'+'0'*(n-2)
插入了空格