Day 8: minimumBy and unlines are a thing

This commit is contained in:
shu 2019-12-08 07:25:22 +01:00
parent 8400b5d393
commit e598a06bc8

View File

@ -1,6 +1,7 @@
{-# LANGUAGE LambdaCase #-}
import Data.List.Split
import Data.List
import Data.Ord
main = do
content <- chunksOf (25*6) <$> head <$> lines <$> readFile "input"
@ -11,7 +12,7 @@ count x = (length . filter (==x))
day8a xs = let l = toLayers xs in
(count '2' l) * (count '1' l)
where toLayers xs = snd $ minimum [(count '0' x, x) | x <- xs]
where toLayers xs = minimumBy (comparing (count '0')) xs
day8b xs = intercalate "\n" $ map (map (\case '0'->' ';'1'->'•')) $ chunksOf 25 img
day8b xs = unlines $ map (map (\case '0'->' ';'1'->'•')) $ chunksOf 25 img
where img = map (head . filter (/='2')) $ transpose xs