From 07d97e193b8f19702a5371741b72f57267c9b2ef Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Sun, 12 Dec 2021 17:36:12 +0100 Subject: WIP 11 --- 2021/11.hs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 2021/11.hs diff --git a/2021/11.hs b/2021/11.hs new file mode 100644 index 0000000..cf23cec --- /dev/null +++ b/2021/11.hs @@ -0,0 +1,31 @@ +{-# OPTIONS -Wno-type-defaults #-} +module Main where + +import qualified Data.Array as A +import Data.List +import Data.Maybe + +import Input + + +stencil8 :: (a -> [a] -> b) -> a -> A.Array (Int, Int) a -> A.Array (Int, Int) b +stencil8 f def arr = + A.listArray (A.bounds arr) + [f (arr A.! (y, x)) + [get (yi, xi) + | yi <- [y-1 .. y+1] + , xi <- [x-1 .. x+1] + , xi /= 0 || yi /= 0] + | y <- [y1..y2], x <- [x1..x2]] + where + get (y, x) | y1 <= y, y <= y2, x1 <= x, x <= x2 = arr A.! (y, x) + | otherwise = def + ((y1, x1), (y2, x2)) = A.bounds arr + +step1 :: A.Array (Int, Int) Int -> A.Array (Int, Int) Int +step1 = stencil _ 0 + +main :: IO () +main = do + inp <- getInput 11 + return () -- cgit v1.2.3-70-g09d2