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 06:13, 4 August 2021
, 2 years ago→{{header|Pascal}}: updated speed by only change the new elements in the middle of the row before.
m (→{{header|Python}}: : arbitrary matrix size printing) |
(→{{header|Pascal}}: updated speed by only change the new elements in the middle of the row before.) |
||
Line 884:
=={{header|Pascal}}==
Using symmetry within row and col.Fill only the middle and let the values before in place.
<lang pascal>program mindistance;
{$IFDEF FPC} //used fpc 3.2.1
Line 902 ⟶ 901:
var
dgtwidth : NativeUint;
function CalcDigitWidth(n: NativeUint):NativeUint;
begin
result:=
while n>= 10 do
Begin
Line 914 ⟶ 913:
end;
procedure OutOneRow(var
var
one_digit,one_row :string;
Line 920 ⟶ 919:
begin
one_row:= '';
For i := low(
begin
str(
one_row += one_digit;
end;
Line 931 ⟶ 930:
var
pRes : tpMinDist;
begin
//iniated with 0
setlength(OneRowElems,MaxCoor);
MaxCoor -= 1;//= High(OneRowElems);
pRes := @OneRowElems[0];
row :=
repeat
if
//fill the inner rest with min_dist
FillDWord(pRes[min_dist],(MaxCoor-2*min_dist+1),min_dist);
OutOneRow(
until row < 0;
writeln;
setlength(
end;
Line 971 ⟶ 964:
Begin
// Test(200*1000);// without output TIO.RUN Real time: 4.152 s CPU share: 97.70 %
Test(23);
Test(10);
Test(9);
Test(1);
end.
</lang>
{{out}}
<pre style="width: 800px; height: 480px>
TIO.RUN
Minimum number of cells after, before, above and below 23 x 23 square:
0 0 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 1 1 0
0 1 2 2 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 3 3 2 1 0
0 1 2 3 4 4 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 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 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 1 x 1 square:
0
</pre>
=={{header|Perl}}==
|