Minimum number of cells after, before, above and below NxN squares: Difference between revisions

→‎{{header|ALGOL W}}: Ensure all cell counts are printed in the same width.
(→‎{{header|ALGOL 68}}: Ensure the cell counts are all displayed in the same width)
(→‎{{header|ALGOL W}}: Ensure all cell counts are printed in the same width.)
Line 101:
=={{header|ALGOL W}}==
{{Trans|Wren}}
This version avoids generating an explicit list of elements for each row in the matrix and just prints the elements as they are calculated. The elements are all shown in the same field width.
<lang algolw>begin % show the minimum number of cells above, below, before and after each %
% cell in a square matrix %
Line 117:
procedure printMinCells ( integer value n ) ;
begin
w := 1; v := ( ( n - ( if odd( n ) then 1 else 0 ) ) div 2 );
while v > 9 do begin v := v div 10; w := w + 1 end;
write( i_w := 1, s_w := 0, "Minimum number of cells after, before, above and below ", n, " x ", n, " square:" );
write();
for r := 0 until n - 1 do begin
for c := 0 until n - 1 do writeon( i_w := 1w, s_w := 1, min4( n-r-1, r, c, n-c-1 ) );
write()
end for_r
Line 159 ⟶ 161:
Minimum number of cells after, before, above and below 1 x 1 square:
0
 
</pre>
Minimum number of cells after, before, above and below 21 x 21 square:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0
0 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 0
0 1 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 2 1 0
0 1 2 3 4 4 4 4 4 4 4 4 4 4 4 4 4 3 2 1 0
0 1 2 3 4 5 5 5 5 5 5 5 5 5 5 5 4 3 2 1 0
0 1 2 3 4 5 6 6 6 6 6 6 6 6 6 5 4 3 2 1 0
0 1 2 3 4 5 6 7 7 7 7 7 7 7 6 5 4 3 2 1 0
0 1 2 3 4 5 6 7 8 8 8 8 8 7 6 5 4 3 2 1 0
0 1 2 3 4 5 6 7 8 9 9 9 8 7 6 5 4 3 2 1 0
0 1 2 3 4 5 6 7 8 9 10 9 8 7 6 5 4 3 2 1 0
0 1 2 3 4 5 6 7 8 9 9 9 8 7 6 5 4 3 2 1 0
0 1 2 3 4 5 6 7 8 8 8 8 8 7 6 5 4 3 2 1 0
0 1 2 3 4 5 6 7 7 7 7 7 7 7 6 5 4 3 2 1 0
0 1 2 3 4 5 6 6 6 6 6 6 6 6 6 5 4 3 2 1 0
0 1 2 3 4 5 5 5 5 5 5 5 5 5 5 5 4 3 2 1 0
0 1 2 3 4 4 4 4 4 4 4 4 4 4 4 4 4 3 2 1 0
0 1 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 2 1 0
0 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 0
0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0</pre>
 
=={{header|Excel}}==
3,038

edits