summaryrefslogtreecommitdiff
path: root/2019/8.hs
diff options
context:
space:
mode:
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')