summaryrefslogtreecommitdiff
path: root/2021
diff options
context:
space:
mode:
Diffstat (limited to '2021')
-rw-r--r--2021/11.hs31
1 files changed, 31 insertions, 0 deletions
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 ()