Sha256: 8d3cc09baf0c27b902be192d74aba2593daff0d9222f9d2c5006ca54ffc0b2c9
Contents?: true
Size: 786 Bytes
Versions: 396
Compression:
Stored size: 786 Bytes
Contents
module Minesweeper (annotate) where import Data.Char (intToDigit) import Data.Maybe (mapMaybe) annotate :: [String] -> [String] annotate xss = [[ fixTile x (i, j) | (j, x ) <- zip [0..] xs ] | (i, xs) <- zip [0..] xss ] where bombs = length . filter (== '*') . mapMaybe (`lookup` tiles) . neighbors fixTile ' ' position = case bombs position of 0 -> ' ' x -> intToDigit x fixTile x _ = x neighbors (i, j) = [ (i - 1, j - 1), (i - 1, j), (i - 1, j + 1) , (i , j - 1), (i , j + 1) , (i + 1, j - 1), (i + 1, j), (i + 1, j + 1) ] tiles = [ ((i, j), x) | (i, xs) <- zip [0 :: Int ..] xss , (j, x ) <- zip [0 :: Int ..] xs ]
Version data entries
396 entries across 396 versions & 1 rubygems