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 07:24, 16 October 2022
, 1 year ago→{{header|Haskell}}
m (→{{header|Minimal BASIC}}: Corrected. A statement after THEN is contrary to the Minimal BASIC standard (though works with most implementations). Only line numbers are allowed there.) |
|||
Line 1,408:
<syntaxhighlight lang="haskell">import Data.Matrix ( matrix, Matrix )
----------- SHORTEST DISTANCES TO EDGE OF MATRIX ---------
distanceToEdge :: Int -> Matrix Int▼
(\(a, b) -> minimum [pred a, pred b, n - a, n - b])▼
distancesToEdge n = matrix n n
--------------------------- TEST -------------------------
main :: IO ()
▲ mapM_ print $ distanceToEdge <$> [10, 9, 2, 1]</syntaxhighlight>
{{Out}}
<pre>┌ ┐
|