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)
cardP :: Parser Card
handsP = handP `sepBy` endOfLine
-handP = Hand <$> ((many1 cardP) <* space) <*> decimal
+handP = Hand <$> many1 cardP <* space <*> decimal
cardP = (Two <$ "2") <|> (Three <$ "3") <|> (Four <$ "4") <|>
(Five <$ "5") <|> (Six <$ "6") <|> (Seven <$ "7") <|>