From: Neil Smith Date: Thu, 7 Dec 2023 12:13:35 +0000 (+0000) Subject: More tinkering X-Git-Url: https://git.njae.me.uk/?a=commitdiff_plain;h=c4136e04dca618af23f2bbc30dc1045afb8a6bac;p=advent-of-code-23.git More tinkering --- diff --git a/advent07/Main.hs b/advent07/Main.hs index b839511..8f4350d 100644 --- a/advent07/Main.hs +++ b/advent07/Main.hs @@ -40,10 +40,7 @@ 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) diff --git a/advent07/MainWithCase.hs b/advent07/MainWithCase.hs index 36b4cd8..e5a181f 100644 --- a/advent07/MainWithCase.hs +++ b/advent07/MainWithCase.hs @@ -40,10 +40,7 @@ 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) =