summaryrefslogtreecommitdiff
path: root/2019/8.hs
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2019-12-08 09:26:00 +0100
committertomsmeding <tom.smeding@gmail.com>2019-12-08 09:26:00 +0100
commit133fe11129d0022329a85c5c0b39d4eefcc378ca (patch)
tree6f2057c3acf9922bbec26bf43ae99cb6b3ead283 /2019/8.hs
parent846fdc733023dfad5399e1017d1e2b369806b788 (diff)
Day 8
Diffstat (limited to '2019/8.hs')
-rw-r--r--2019/8.hs24
1 files changed, 24 insertions, 0 deletions
diff --git a/2019/8.hs b/2019/8.hs
new file mode 100644
index 0000000..e9f269b
--- /dev/null
+++ b/2019/8.hs
@@ -0,0 +1,24 @@
+module Main where
+
+import Data.List
+import Data.Ord
+
+import Input
+
+
+blockBy :: Int -> [a] -> [[a]]
+blockBy _ [] = []
+blockBy n l = uncurry (:) (fmap (blockBy n) (splitAt n l))
+
+main :: IO ()
+main = do
+ layers <- blockBy (25 * 6) . head <$> getInput 8
+
+ let count x = length . filter (== x)
+ layer = minimumBy (comparing (count '0')) layers
+ print (count '1' layer * count '2' layer)
+
+ let combine = zipWith (\a b -> if a == '2' then b else a)
+ image = foldl1 combine layers
+ image' = map (\c -> if c == '1' then '#' else '.') image
+ mapM_ putStrLn (blockBy 25 image')