From: Neil Smith Date: Thu, 5 Dec 2024 15:23:04 +0000 (+0000) Subject: Tidying X-Git-Url: https://git.njae.me.uk/?a=commitdiff_plain;h=b4c85c187f3ac96efcd95fcf0e93363ff288b61f;p=advent-of-code-24.git Tidying --- diff --git a/advent05/MainOrdering.hs b/advent05/MainOrdering.hs index 8f2f8e9..6ed5b47 100644 --- a/advent05/MainOrdering.hs +++ b/advent05/MainOrdering.hs @@ -40,17 +40,11 @@ part2 rules books = sum $ fmap middlePage reorderedBooks -- a EQ b if there is no rule about the order of a and b pageOrder :: Rules -> Page -> Page -> Ordering pageOrder rules a b - | isNothing pa && isNothing pb = EQ - | isNothing pa = LT - | isNothing pb = GT | S.member a rb = LT | S.member b ra = GT | otherwise = EQ - where pa = rules M.!? a - pb = rules M.!? b - ra = fromJust pa - rb = fromJust pb - + where ra = M.findWithDefault S.empty a rules + rb = M.findWithDefault S.empty b rules middlePage :: [Page] -> Page middlePage b = b !! (length b `div` 2)