Minimum number of cells after, before, above and below NxN squares: Difference between revisions
Minimum number of cells after, before, above and below NxN squares (view source)
Revision as of 23:03, 31 October 2021
, 2 years ago→{{header|Ruby}}: Add ruby
(→{{header|ALGOL W}}: Added missing declarations) |
(→{{header|Ruby}}: Add ruby) |
||
Line 1,599:
</pre>
=={{header|Ruby}}==
<lang ruby>def dist2edge(n)
width = (n/2).to_s.size+1
m = n-1
(0..m).map do |x|
(0..m).map{|y| [x, y, m-x, m-y].min.to_s.center(width) }.join
end
end
puts dist2edge(10)</lang>
{{out}}
<pre>0 0 0 0 0 0 0 0 0 0
0 1 1 1 1 1 1 1 1 0
0 1 2 2 2 2 2 2 1 0
0 1 2 3 3 3 3 2 1 0
0 1 2 3 4 4 3 2 1 0
0 1 2 3 4 4 3 2 1 0
0 1 2 3 3 3 3 2 1 0
0 1 2 2 2 2 2 2 1 0
0 1 1 1 1 1 1 1 1 0
0 0 0 0 0 0 0 0 0 0
</pre>
=={{header|Wren}}==
{{libheader|Wren-math}}
|