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

m
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
distanceToEdge n =
matrix
n
n
(\(a, b) -> minimum [pred a, pred b, n - a, n - b])
 
distanceToEdgedistancesToEdge :: Int -> Matrix Int
distancesToEdge n = matrix n n
(\(ai, bj) -> minimum [pred$ a,($) pred<$> b[pred, (n -)] a,<*> n -[i, bj])
 
 
--------------------------- TEST -------------------------
main :: IO ()
main = mapM_ print $ distanceToEdgedistancesToEdge <$> [10, 9, 2, 1]</syntaxhighlight>
main =
mapM_ print $ distanceToEdge <$> [10, 9, 2, 1]</syntaxhighlight>
{{Out}}
<pre>┌ ┐
9,655

edits