Day 8: Some cleanup

This commit is contained in:
shu 2019-12-08 07:14:04 +01:00
parent 8413a89bf8
commit 8400b5d393

View File

@ -1,3 +1,4 @@
{-# LANGUAGE LambdaCase #-}
import Data.List.Split
import Data.List
@ -6,9 +7,11 @@ main = do
print (day8a content)
putStrLn (day8b content)
toLayers xs = snd $ minimum [((length . filter (=='0')) x, x) | x <- xs]
day8a xs = let l = toLayers xs in
(length $ filter (=='2') l) * (length $ filter (=='1') l)
count x = (length . filter (==x))
day8b xs = intercalate "\n" $ map (map (\x->if x=='0' then ' ' else '•')) $ chunksOf 25 img
where img = map (foldr (\x y->if x=='2' then y else x) '2') $ transpose xs
day8a xs = let l = toLayers xs in
(count '2' l) * (count '1' l)
where toLayers xs = snd $ minimum [(count '0' x, x) | x <- xs]
day8b xs = intercalate "\n" $ map (map (\case '0'->' ';'1'->'•')) $ chunksOf 25 img
where img = map (head . filter (/='2')) $ transpose xs