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

Line 1,527:
│ │ │ │0 0 0 0 0 0 0 0 0 0│
└───┴─────┴─────────────────┴───────────────────┘</pre>
 
=={{header|jq}}==
{{works with|jq}}
'''Also works with gojq, the Go implementation of jq'''
 
'''Also works with fq, a Go implementation of a large subset of jq'''
<syntaxhighlight lang=jq>
def lpad($len): tostring | ($len - length) as $l | (" " * $l)[:$l] + .;
 
def printMinCells:
"Minimum number of cells after, before, above and below each cell in a \(.) x \(.) matrix:",
( (. / 2 | ceil | tostring | length) as $p
| range(0; .) as $r
| [ range(0; .) as $c
| [. - $r - 1, $r, $c, . - $c - 1] | min | lpad($p)] | join(" ") );
 
23, 10, 9, 2, 1
| printMinCells, ""
</syntaxhighlight>
{{output}}
As expected.
 
=={{header|Julia}}==
2,492

edits