feat: part 2-2

This commit is contained in:
Kiana Sheibani 2024-12-03 04:06:45 -05:00
parent fad1b50858
commit bf184dd8d3
Signed by: toki
GPG key ID: 6CB106C25E86A9F7
4 changed files with 30 additions and 2 deletions

View file

@ -15,4 +15,4 @@ main = Main
modules = Main, Utils, AllDays,
Data.Problem,
Day1.Part1, Day1.Part2,
Day2.Part1
Day2.Part1, Day2.Part2

View file

@ -3,3 +3,4 @@ module AllDays
import public Day1.Part1
import public Day1.Part2
import public Day2.Part1
import public Day2.Part2

27
src/Day2/Part2.idr Normal file
View file

@ -0,0 +1,27 @@
module Day2.Part2
import Data.List
import Data.List1
import Data.String
import Utils
import Day2.Part1
%default total
--- DATA
reductions : Report -> List Report
reductions (x ::: []) = []
reductions (x ::: [y]) = [y ::: [], x ::: []]
reductions (x ::: (y :: xs)) =
(y ::: xs) :: map (x `cons`) (assert_total $ reductions (y ::: xs))
isSafe' : Report -> Bool
isSafe' rep = isSafe rep || any isSafe (reductions rep)
--- SOLUTION
export
solution : String -> Maybe Nat
solution inp = count isSafe' <$> parseInput inp

View file

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