的JavaScript(ES6),114个 106 105 104 103字节
n=>(g=x=>v=x*2>w?w-x:x,F=x=>~y?`#
`[~x?(h=g(x--))*g(y)>0&h+v!=n|n>h+v:(y--,x=w,2)]+F(x):'')(y=w=--n*3)
在线尝试!
怎么样?
这将逐字符构建输出。
给定输入ñ,我们计算:
ñ′= n − 1w = 3 n′
对于(x,y)处的每个字符,我们计算(h,v):
h=w/2−|x−w/2|v=w/2−|y−w/2|
属于八边形的像元满足以下条件之一:
- (h=0 OR v=0)AND h+v≥n′(在下文中红色)
- h+v=n′(在下面的橙色)
例如,当n=4(并且n′=3)时:
(0,0)(0,1)(0,2)(0,3)(0,4)(0,4)(0,3)(0,2)(0,1)(0,0)(1,0)(1,1)(1,2)(1,3)(1,4)(1,4)(1,3)(1,2)(1,1)(1,0)(2,0)(2,1)(2,2)(2,3)(2,4)(2,4)(2,3)(2,2)(2,1)(2,0)(3,0)(3,1)(3,2)(3,3)(3,4)(3,4)(3,3)(3,2)(3,1)(3 ,0)(4,0)(4,1)(4,2)(4,3)(4,4)(4,4)(4,3)(4,2)(4,1)(4 ,0)(4,0)(4,1)(4,2)(4,3)(4,4)(4,4)(4,3)(4,2)(4,1)(4 ,0)(3,0)(3,1)(3,2)(3,3)(3,4)(3,4)(3,3)(3,2)(3,1)(3 ,0)(2,0)(2,1)(2,2)(2,3)(2,4)(2,4)(2,3)(2,2)(2,1)(2 ,0)(1,0)(1,1)(1,2)(1,3)(1,4)(1,4)(1,3)(1,2)(1,1)(1 ,0)(0,0)(0,1)(0,2)(0 ,3)(0 , 4 )(0 ,4)(0 , 3 )(0,2 )(0,1 )(0 ,0 )