feat: part 3-2
This commit is contained in:
parent
939f596c34
commit
b37d5f2dd4
|
@ -17,4 +17,4 @@ modules = Main, Utils, AllDays,
|
|||
Data.Problem,
|
||||
Day1.Part1, Day1.Part2,
|
||||
Day2.Part1, Day2.Part2,
|
||||
Day3.Part1
|
||||
Day3.Part1, Day3.Part2
|
||||
|
|
|
@ -5,3 +5,4 @@ import public Day1.Part2
|
|||
import public Day2.Part1
|
||||
import public Day2.Part2
|
||||
import public Day3.Part1
|
||||
import public Day3.Part2
|
||||
|
|
26
src/Day3/Part2.idr
Normal file
26
src/Day3/Part2.idr
Normal file
|
@ -0,0 +1,26 @@
|
|||
module Day3.Part2
|
||||
|
||||
import Data.Either
|
||||
import Data.Maybe
|
||||
import Data.String
|
||||
import Data.String.Parser
|
||||
import Utils
|
||||
|
||||
import Day3.Part1
|
||||
|
||||
--- PARSING
|
||||
|
||||
export
|
||||
mulsDo : Parser (List Integer)
|
||||
mulsDo = map join $ many $ do
|
||||
s <- scan $ string "do()" <|> string "don't()"
|
||||
if s == "do()"
|
||||
then many $ scanWhile (requireFailure (string "do()" <|> string "don't()")) mul
|
||||
else pure []
|
||||
|
||||
--- SOLUTION
|
||||
|
||||
export
|
||||
solution : String -> Integer
|
||||
solution = fromMaybe 0 . map (sum . fst) . eitherToMaybe .
|
||||
parse mulsDo . ("do()" ++)
|
|
@ -14,7 +14,7 @@ import AllDays
|
|||
||| The latest problem that has been solved.
|
||||
-- NOTE: UPDATE AFTER EACH SOLUTION
|
||||
latest : Problem
|
||||
latest = Pr 3 Part1
|
||||
latest = Pr 3 Part2
|
||||
|
||||
|
||||
solMap : SortedMap Problem (String -> String)
|
||||
|
|
Loading…
Reference in a new issue