自动房屋建造纳米机器人已经被制造出来,你的工作就是对它们进行编码。
这是由输入7 4 2创建的房子
/-----/|
/ / |
|-----| |
| | |
| | /
|_____|/输入是一个包含房屋尺寸的字符串。
7是宽度。
|_____|
---7---4是身高。
|
|
|
|2是深度
/
/有了这个输入,你能创造房子吗?
你的代码必须尽可能小,这样它才能适应机器人。
您将作为输入的最小维度是3 2 2。你的程序可以做任何尺寸比3 2 2小的事情。
3 2 10
/-/|
/ / |
/ / /
/ / /
/ / /
/ / /
/ / /
/ / /
/ / /
/ / /
|-| /
|_|/发布于 2016-05-03 07:57:22
w,h,d=input();i=d
while-i<h:c='|/'[i>0];print' '*i+c+'- _'[(d>i!=0)+(h+i<2)]*(w-2)+c+' '*min(d-i,h-1,w+1,h-1+i)+'/|'[d-i<h];i-=1逐行打印。行索引i从d向下计数到-h+1。
发布于 2016-05-02 11:46:31
(w,h,d)=>[...Array(d+h--)].map((_,i)=>` `[r=`repeat`](i<d&&d-i)+(c=`|/`[+(i<d)])+` _-`[i&&i-d?h+d-i?0:1:2][r](w-2)+c+` `[r]((i<d?i:d)-(i>h&&i-h))+`|/`[+(i>h)]).join`\n`其中\n表示文字换行符。解释:
(w,h,d,)=> Parameters
[...Array(d+h--)].map((_,i)=> Loop over total height = d + h
` `[r=`repeat`](i<d&&d-i)+ Space before roof (if applicable)
(c=`|/`[+(i<d)])+ Left wall/roof edge
` _-`[i&&i-d?h+d-i?0:1:2][r](w-2)+ Space, floor or eaves between walls
c+ Right wall/roof edge (same as left)
` `[r]((i<d?i:d)-(i>h&&i-h))+ Right wall
`|/`[+(i>h)] Back wall/floor edge
).join` Join everything together
`编辑:由于@jrich保存了2个字节。
发布于 2016-05-02 23:30:10
返回字符串列表。列表中的每个元素对应于一行。如果必须返回多行字符串,请在最后一个括号之前添加3个字节以添加*$/。
->w,h,d{s=' ';(0..m=d+h-1).map{|i|(i<d ?s*(d-i)+?/:?|)+(i<1||i==d ??-:i==m ??_ :s)*(w-2)+(i<d ? ?/:?|)+(i<h ?s*[i,d].min+?|:s*[m-i,h-1].min+?/)}}https://codegolf.stackexchange.com/questions/79033
复制相似问题