Anonymous user
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 16:09, 2 August 2021
, 2 years ago→{{header|Nim}}
(Added Go) |
|||
Line 162:
0
</pre>
=={{header|Nim}}==
{{trans|Go}}
<lang Nim>import strutils
proc printMinCells(n: Positive) =
echo "Minimum number of cells after, before, above and below $1 x $1 square:".format(n)
var cells = newSeq[int](n)
for r in 0..<n:
for c in 0..<n:
cells[c] = min([n - r - 1, r, c, n - c - 1])
echo cells.join(" ")
when isMainModule:
for n in [10, 9, 2, 1]:
printMinCells(n)
echo()</lang>
{{out}}
<pre>Minimum number of cells after, before, above and below 10 x 10 square:
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
Minimum number of cells after, before, above and below 9 x 9 square:
0 0 0 0 0 0 0 0 0
0 1 1 1 1 1 1 1 0
0 1 2 2 2 2 2 1 0
0 1 2 3 3 3 2 1 0
0 1 2 3 4 3 2 1 0
0 1 2 3 3 3 2 1 0
0 1 2 2 2 2 2 1 0
0 1 1 1 1 1 1 1 0
0 0 0 0 0 0 0 0 0
Minimum number of cells after, before, above and below 2 x 2 square:
0 0
0 0
Minimum number of cells after, before, above and below 1 x 1 square:
0</pre>
=={{header|REXX}}==
|