feat: part 3-1
This commit is contained in:
parent
b3c48a5d8c
commit
41de325442
|
@ -9,10 +9,12 @@ license = "MIT"
|
|||
sourcedir = "src"
|
||||
|
||||
langversion >= 0.6.0
|
||||
depends = contrib
|
||||
|
||||
executable = advent-of-code-2024
|
||||
main = Main
|
||||
modules = Main, Utils, AllDays,
|
||||
Data.Problem,
|
||||
Day1.Part1, Day1.Part2,
|
||||
Day2.Part1, Day2.Part2
|
||||
Day2.Part1, Day2.Part2,
|
||||
Day3.Part1
|
||||
|
|
|
@ -4,3 +4,4 @@ import public Day1.Part1
|
|||
import public Day1.Part2
|
||||
import public Day2.Part1
|
||||
import public Day2.Part2
|
||||
import public Day3.Part1
|
||||
|
|
29
src/Day3/Part1.idr
Normal file
29
src/Day3/Part1.idr
Normal file
|
@ -0,0 +1,29 @@
|
|||
module Day3.Part1
|
||||
|
||||
import Data.Either
|
||||
import Data.Maybe
|
||||
import Data.String
|
||||
import Data.String.Parser
|
||||
|
||||
--- PARSING
|
||||
|
||||
export
|
||||
scan : Monad m => ParseT m a -> ParseT m a
|
||||
scan p = many (requireFailure p *> skip (satisfy (const True))) *> p
|
||||
|
||||
export
|
||||
mul : Parser Integer
|
||||
mul = do
|
||||
skip $ string "mul("
|
||||
x <- integer
|
||||
skip $ string ","
|
||||
y <- integer
|
||||
skip $ string ")"
|
||||
pure $ x * y
|
||||
|
||||
--- SOLUTION
|
||||
|
||||
export
|
||||
solution : String -> Integer
|
||||
solution = fromMaybe 0 . map (sum . fst) . eitherToMaybe .
|
||||
parse (many $ scan mul)
|
|
@ -14,7 +14,7 @@ import AllDays
|
|||
||| The latest problem that has been solved.
|
||||
-- NOTE: UPDATE AFTER EACH SOLUTION
|
||||
latest : Problem
|
||||
latest = Pr 2 Part2
|
||||
latest = Pr 3 Part1
|
||||
|
||||
|
||||
solMap : SortedMap Problem (String -> String)
|
||||
|
|
Loading…
Reference in a new issue