summaryrefslogtreecommitdiff
path: root/2021
diff options
context:
space:
mode:
authorTom Smeding <t.j.smeding@uu.nl>2021-12-12 17:36:12 +0100
committerTom Smeding <t.j.smeding@uu.nl>2021-12-12 17:36:12 +0100
commit07d97e193b8f19702a5371741b72f57267c9b2ef (patch)
tree0c0ac840d65c488090762711ddb62556e5f18a47 /2021
parent61ed306db299c171293350ae028be0f9e7f4845b (diff)
WIP 11
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 ()