Done day 24
[advent-of-code-23.git] / advent07 / Main.hs
index 6d326a4f545c08603210a8d9bc73de441fc2a7db..8f4350d293e9fd37abba85ad702396b214a923dd 100644 (file)
@@ -33,17 +33,14 @@ part1 hands = sum $ fmap score rankedHands
         rankedHands = zip [1..] sortedHands
         score (r, CHand _ _ bid) = r * bid
 
-part2 hands = part1 $ fmap enJoker hands
+part2 = part1 . fmap enJoker
 
 enJoker :: Hand -> Hand
 enJoker (Hand cards bid) = Hand jCards bid
   where jCards = replace Jack Joker cards
 
 replace :: Eq a => a -> a -> [a] -> [a]
-replace _ _ [] = []
-replace f t (x:xs) 
-  | x == f = t : replace f t xs
-  | otherwise = x : replace f t xs
+replace f t = fmap (\x -> if x == f then t else x)
 
 classify :: Hand -> ClassifiedHand
 classify (Hand cards bid)