feat: part 7-2
This commit is contained in:
parent
b4391bec86
commit
3826a13244
|
@ -13,3 +13,4 @@ import public Day5.Part2
|
|||
import public Day6.Part1
|
||||
import public Day6.Part2
|
||||
import public Day7.Part1
|
||||
import public Day7.Part2
|
||||
|
|
|
@ -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
21
src/Day7/Part2.idr
Normal 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
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue