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

m
(Added Applesoft BASIC and Chipmunk Basic)
m (→‎{{header|Wren}}: Minor tidy)
(3 intermediate revisions by 2 users not shown)
Line 800:
80 for i = 1 to n
90 for j = 1 to n
100 print using "##"; min(min(i-1,n-i),min(j-1,n-j));" ";
110 next j
120 print
Line 1,604:
|
|}
 
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|SysUtils,StdCtrls}}
The problem is not well described. You have to look at other people's code to understand the problem, which turns out to be something quite different from the description seems to say.
 
<syntaxhighlight lang="Delphi">
 
function EdgeDistance(P: TPoint; Size: integer): integer;
{Find the distance to the nearest edge}
begin
Result:=Min(Min(P.X,(Size-1)-P.X),Min(P.Y,(Size-1)-P.Y));
end;
 
 
procedure MapMatrix(Memo: TMemo; Size: integer);
{Map each cell in Size X Size matrix}
{with the distance to nearest edge}
var X,Y,E: integer;
var S: string;
begin
Memo.Lines.Add(Format('Map for %d X %d Matrix',[Size,Size]));
S:='';
for Y:=0 to Size-1 do
begin
for X:=0 to Size-1 do
begin
E:=EdgeDistance(Point(X,Y),Size);
S:=S+Format('%3d',[E]);
end;
S:=S+#$0D#$0A;
end;
Memo.Lines.Add(S);
end;
 
 
procedure ShowEdgeMaps(Memo: TMemo);
{Show a series of maps for matrices of different sizes}
var I: integer;
begin
for I:=3 to 12 do MapMatrix(Memo,I);
end;
 
</syntaxhighlight>
{{out}}
<pre>
Map for 3 X 3 Matrix
0 0 0
0 1 0
0 0 0
 
Map for 4 X 4 Matrix
0 0 0 0
0 1 1 0
0 1 1 0
0 0 0 0
 
Map for 5 X 5 Matrix
0 0 0 0 0
0 1 1 1 0
0 1 2 1 0
0 1 1 1 0
0 0 0 0 0
 
Map for 6 X 6 Matrix
0 0 0 0 0 0
0 1 1 1 1 0
0 1 2 2 1 0
0 1 2 2 1 0
0 1 1 1 1 0
0 0 0 0 0 0
 
Map for 7 X 7 Matrix
0 0 0 0 0 0 0
0 1 1 1 1 1 0
0 1 2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0
0 1 2 3 4 5 5 4 3 2 1 0
0 1 2 3 4 4 4 4 3 2 1 0
0 1 2 3 3 3 3 3 3 2 1 0
0 1 2 2 2 2 2 2 2 2 1 0
0 1 1 1 1 1 1 1 1 1 1 0
0 0 0 0 0 0 0 0 0 0 0 0
</pre>
 
 
=={{header|F_Sharp|F#}}==
Line 3,001 ⟶ 3,143:
{{libheader|Wren-math}}
{{libheader|Wren-fmt}}
<syntaxhighlight lang="ecmascriptwren">import "./math" for Nums
import "./fmt" for Fmt
 
var printMinCells = Fn.new { |n|
9,483

edits