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 00:53, 15 October 2022
, 1 year agoDialects of BASIC moved to the BASIC section.
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
(Dialects of BASIC moved to the BASIC section.) |
||
Line 389:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
</pre>
=={{header|BASIC}}==
Line 413 ⟶ 412:
Igual que la entrada de FreeBASIC.
</pre>
==={{header|FreeBASIC}}===▼
<syntaxhighlight lang="freebasic">#define min(a, b) Iif(a<=b,a,b)▼
sub minab( n as uinteger )▼
for i as uinteger = 1 to n▼
for j as uinteger = 1 to n▼
print using "## ";min( min(i-1, n-i), min(j-1, n-j) );▼
next j▼
print▼
next i▼
end sub▼
minab(10)</syntaxhighlight>▼
{{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|GW-BASIC}}===▼
<syntaxhighlight lang="gwbasic">10 N = 10▼
20 FOR I = 0 TO N - 1▼
30 IF I < N - 1 - I THEN DI = I ELSE DI = N - 1 - I▼
40 FOR J = 0 TO N - 1▼
50 IF J < N - 1 - J THEN DJ = J ELSE DJ = N - 1 - J▼
60 IF DI < DJ THEN M = DI ELSE M = DJ▼
70 PRINT USING "## ";M;▼
80 NEXT J▼
90 PRINT▼
100 NEXT I</syntaxhighlight>▼
==={{header|QBasic}}===
Line 481 ⟶ 518:
Igual que la entrada de FreeBASIC.
</pre>
=={{header|BCPL}}==
Line 1,145 ⟶ 1,181:
0, 1, 1, 1, 1, 1, 1, 1, 1, 0, `
0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]]
▲</pre>
▲=={{header|FreeBASIC}}==
▲<syntaxhighlight lang="freebasic">#define min(a, b) Iif(a<=b,a,b)
▲sub minab( n as uinteger )
▲ for i as uinteger = 1 to n
▲ for j as uinteger = 1 to n
▲ print using "## ";min( min(i-1, n-i), min(j-1, n-j) );
▲ next j
▲ print
▲ next i
▲end sub
▲minab(10)</syntaxhighlight>
▲{{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>
Line 1,265 ⟶ 1,275:
[0]
</pre>
▲=={{header|GW-BASIC}}==
▲<syntaxhighlight lang="gwbasic">10 N = 10
▲20 FOR I = 0 TO N - 1
▲30 IF I < N - 1 - I THEN DI = I ELSE DI = N - 1 - I
▲40 FOR J = 0 TO N - 1
▲50 IF J < N - 1 - J THEN DJ = J ELSE DJ = N - 1 - J
▲60 IF DI < DJ THEN M = DI ELSE M = DJ
▲70 PRINT USING "## ";M;
▲80 NEXT J
▲90 PRINT
▲100 NEXT I</syntaxhighlight>
=={{header|Haskell}}==
|