Solve day 5 part 1
This commit is contained in:
parent
3742e1d254
commit
62be96ed57
@ -1,15 +1,42 @@
|
||||
module Puzzles.Day5 (puzzle) where
|
||||
|
||||
import Control.Monad
|
||||
import Data.Functor
|
||||
import Data.List.Extra
|
||||
import Data.Maybe
|
||||
import Data.Text.Lazy qualified as TL
|
||||
import Puzzle
|
||||
import Text.Megaparsec hiding (some)
|
||||
import Text.Megaparsec.Char
|
||||
import Text.Megaparsec.Char.Lexer qualified as Lex
|
||||
|
||||
puzzle :: Puzzle
|
||||
puzzle =
|
||||
Puzzle
|
||||
{ number = 5
|
||||
, parser = pure ()
|
||||
, parser = do
|
||||
ranges <- flip sepEndBy newline $ Range <$> Lex.decimal <* single '-' <*> Lex.decimal
|
||||
void newline
|
||||
vals <- sepEndBy Lex.decimal newline
|
||||
pure (ranges, vals)
|
||||
, parts =
|
||||
[ \() ->
|
||||
"TODO"
|
||||
[ \(ranges, vals) ->
|
||||
TL.show
|
||||
. length
|
||||
. map fst
|
||||
. filter (notNull . snd)
|
||||
$ map
|
||||
(\v -> (v, mapMaybe (\r -> guard (isInRange v r) $> r) ranges))
|
||||
vals
|
||||
]
|
||||
, extraTests = mempty
|
||||
}
|
||||
|
||||
data Range = Range
|
||||
{ lower :: Int
|
||||
, upper :: Int
|
||||
}
|
||||
deriving (Eq, Ord, Show)
|
||||
|
||||
isInRange :: Int -> Range -> Bool
|
||||
isInRange n r = n >= r.lower && n <= r.upper
|
||||
|
||||
1
outputs/real/5/1
Normal file
1
outputs/real/5/1
Normal file
@ -0,0 +1 @@
|
||||
874
|
||||
Loading…
x
Reference in New Issue
Block a user