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

Add CLU
(Minimum number of cells after, before, above and below NxN squares in various BASIC dialents)
(Add CLU)
Line 455:
0 0 0 0 0 0 0 0 0 0
</pre>
 
=={{header|CLU}}==
<lang clu>min = proc [T: type] (a, b: T) returns (T)
where T has lt: proctype (T,T) returns (bool)
if a<b
then return(a)
else return(b)
end
end min
 
min_n_by_n = proc (n: int) returns (array[array[int]])
ai = array[int]
aai = array[ai]
t: aai := aai$[]
for y: int in int$from_to(0, n-1) do
aai$addh(t, ai$[])
for x: int in int$from_to(0, n-1) do
i: int := min[int](x, min[int](n-x-1, min[int](y, n-y-1)))
ai$addh(aai$top(t), i)
end
end
return(t)
end min_n_by_n
 
print_table = proc (s: stream, table: array[array[int]])
ai = array[int]
aai = array[ai]
for line: ai in aai$elements(table) do
for item: int in ai$elements(line) do
stream$puts(s, int$unparse(item) || " ")
end
stream$putl(s, "")
end
end print_table
 
start_up = proc ()
print_table(stream$primary_output(), min_n_by_n(10))
end start_up</lang>
{{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|COBOL}}==
2,114

edits