From e598a06bc862bdb18c258d012e4cb4205223d99c Mon Sep 17 00:00:00 2001 From: shu Date: Sun, 8 Dec 2019 07:25:22 +0100 Subject: [PATCH] Day 8: minimumBy and unlines are a thing --- 2019/day8/day8.hs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/2019/day8/day8.hs b/2019/day8/day8.hs index f317ad8..43d3d8b 100644 --- a/2019/day8/day8.hs +++ b/2019/day8/day8.hs @@ -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