|
| 1 | +{-# LANGUAGE BlockArguments #-} |
| 2 | +{-# LANGUAGE NoImplicitPrelude #-} |
| 3 | + |
| 4 | +module AdventOfCode.Year2025.Day05 where |
| 5 | + |
| 6 | +import AdventOfCode.Input (parseInputAoC, parseString) |
| 7 | +import AdventOfCode.Puzzle |
| 8 | +import AdventOfCode.TH (defaultMainPuzzle) |
| 9 | +import AdventOfCode.Util (count) |
| 10 | +import Data.Ix (inRange) |
| 11 | +import Relude |
| 12 | +import Text.Trifecta (Parser, char, decimal, newline, sepEndBy) |
| 13 | + |
| 14 | +database :: Parser ([(Integer, Integer)], [Integer]) |
| 15 | +database = do |
| 16 | + idRange <- some $ do |
| 17 | + from <- decimal <* char '-' |
| 18 | + to <- decimal <* newline |
| 19 | + pure (from, to) |
| 20 | + ingredients <- newline *> decimal `sepEndBy` newline |
| 21 | + pure (idRange, ingredients) |
| 22 | + |
| 23 | +getExample :: IO ([(Integer, Integer)], [Integer]) |
| 24 | +getExample = parseString database example |
| 25 | + |
| 26 | +example :: String |
| 27 | +example = |
| 28 | + "3-5\n\ |
| 29 | + \10-14\n\ |
| 30 | + \16-20\n\ |
| 31 | + \12-18\n\ |
| 32 | + \\n\ |
| 33 | + \1\n\ |
| 34 | + \5\n\ |
| 35 | + \8\n\ |
| 36 | + \11\n\ |
| 37 | + \17\n\ |
| 38 | + \32" |
| 39 | + |
| 40 | +getInput :: IO ([(Integer, Integer)], [Integer]) |
| 41 | +getInput = parseInputAoC 2025 5 database |
| 42 | + |
| 43 | +partOne :: SimplePuzzle ([(Integer, Integer)], [Integer]) Int |
| 44 | +partOne = |
| 45 | + asks \(ranges, ingredients) -> |
| 46 | + count (flip any ranges . flip inRange) ingredients |
| 47 | + |
| 48 | +partTwo :: SimplePuzzle ([(Integer, Integer)], [Integer]) () |
| 49 | +partTwo = fail "not yet implemented" |
| 50 | + |
| 51 | +main :: IO () |
| 52 | +main = $(defaultMainPuzzle) |
0 commit comments