feat: part 7-2

This commit is contained in:
Kiana Sheibani 2024-12-09 00:46:19 -05:00
parent b4391bec86
commit 3826a13244
Signed by: toki
GPG key ID: 6CB106C25E86A9F7
4 changed files with 26 additions and 1 deletions

View file

@ -13,3 +13,4 @@ import public Day5.Part2
import public Day6.Part1
import public Day6.Part2
import public Day7.Part1
import public Day7.Part2

View file

@ -9,6 +9,7 @@ import Utils
--- TYPES
public export
Op : Type
Op = Nat -> Nat -> Nat
@ -21,11 +22,13 @@ parseLine inp =
in (,) <$> parseNat part1
<*> (traverse parseNat =<< fromList (words part2))
export
parseInput : String -> Maybe (List (Nat, List1 Nat))
parseInput = traverse parseLine . lines
--- DATA
export
search : List Op -> (tg, tot : Nat) -> List Nat -> Bool
search _ tg tot [] = tg == tot
search ops tg tot (x :: xs) =

21
src/Day7/Part2.idr Normal file
View file

@ -0,0 +1,21 @@
module Day7.Part2
import Data.List1
import Day7.Part1
import Utils
%default total
--- DATA
concat : Nat -> Nat -> Nat
concat x y = cast $ show x ++ show y
--- SOLUTION
export
solution : String -> Maybe Nat
solution = map (sum . map fst
. filter (\(tg,x:::xs) => search [(+),(*),concat] tg x xs))
. parseInput

View file

@ -13,7 +13,7 @@ import AllDays
||| The latest problem that has been solved.
-- NOTE: UPDATE AFTER EACH SOLUTION
latest : Problem
latest = Pr 7 Part1
latest = Pr 7 Part2
solMap : SortedMap Problem (String -> String)