From 5bf3f4e0cebe3af142c7308b144f2275050949f8 Mon Sep 17 00:00:00 2001 From: Xiretza Date: Wed, 16 Dec 2020 17:56:44 +0100 Subject: [PATCH] day16/haskell: readability improvements --- 2020/day16/day16.hs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/2020/day16/day16.hs b/2020/day16/day16.hs index b5ccf44..f135d47 100644 --- a/2020/day16/day16.hs +++ b/2020/day16/day16.hs @@ -53,7 +53,7 @@ parseInput = do return $ Input {fields, myTicket, otherTickets } matchesAnyField :: [Field] -> Int -> Bool -matchesAnyField fields n = any (n `S.member`) . map valids $ fields +matchesAnyField fields n = any ((n `S.member`) . valids) fields iterateUntilNothing :: (a -> Maybe a) -> a -> a iterateUntilNothing f x = maybe x (iterateUntilNothing f) $ f x @@ -75,10 +75,10 @@ findSingletonChoice (x:xs) = resolve' :: Ord a => [Resolve a] -> Maybe [Resolve a] resolve' xs = do - (x, xs') <- findSingletonChoice xs - return $ map (dropChoice x) xs' + (r, xs') <- findSingletonChoice xs + return $ map (dropChoice r) xs' where dropChoice x (Choice s) = Choice (S.delete x s) - dropChoice _ r = r + dropChoice _ y = y part1 :: Input -> Int part1 Input { fields, otherTickets } = sum . filter (not . matchesAnyField fields) . concat $ otherTickets