projects
/
advent-of-code-23.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Tidying, mainly parsers
[advent-of-code-23.git]
/
advent07
/
MainWithCase.hs
diff --git
a/advent07/MainWithCase.hs
b/advent07/MainWithCase.hs
index 36b4cd86a5178b4db55be5da2de60862907cc016..bd0aa85906dab170f5235500673f0ca25d3786f7 100644
(file)
--- 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]
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) =
classify :: Hand -> ClassifiedHand
classify (Hand cards bid) =
@@
-74,7
+71,7
@@
handP :: Parser Hand
cardP :: Parser Card
handsP = handP `sepBy` endOfLine
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") <|>
cardP = (Two <$ "2") <|> (Three <$ "3") <|> (Four <$ "4") <|>
(Five <$ "5") <|> (Six <$ "6") <|> (Seven <$ "7") <|>