From b4c85c187f3ac96efcd95fcf0e93363ff288b61f Mon Sep 17 00:00:00 2001 From: Neil Smith Date: Thu, 5 Dec 2024 15:23:04 +0000 Subject: [PATCH] Tidying --- advent05/MainOrdering.hs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) 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) -- 2.34.1