From c4136e04dca618af23f2bbc30dc1045afb8a6bac Mon Sep 17 00:00:00 2001 From: Neil Smith Date: Thu, 7 Dec 2023 12:13:35 +0000 Subject: [PATCH] More tinkering --- advent07/Main.hs | 5 +---- advent07/MainWithCase.hs | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) 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) = -- 2.34.1