From bf184dd8d3ce7af39b0a6850686f0a4ca81a7cb2 Mon Sep 17 00:00:00 2001 From: Kiana Sheibani Date: Tue, 3 Dec 2024 04:06:45 -0500 Subject: [PATCH] feat: part 2-2 --- advent-of-code-2024.ipkg | 2 +- src/AllDays.idr | 1 + src/Day2/Part2.idr | 27 +++++++++++++++++++++++++++ src/Main.idr | 2 +- 4 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 src/Day2/Part2.idr diff --git a/advent-of-code-2024.ipkg b/advent-of-code-2024.ipkg index ae79350..764448c 100644 --- a/advent-of-code-2024.ipkg +++ b/advent-of-code-2024.ipkg @@ -15,4 +15,4 @@ main = Main modules = Main, Utils, AllDays, Data.Problem, Day1.Part1, Day1.Part2, - Day2.Part1 + Day2.Part1, Day2.Part2 diff --git a/src/AllDays.idr b/src/AllDays.idr index 27c663c..e3d32ef 100644 --- a/src/AllDays.idr +++ b/src/AllDays.idr @@ -3,3 +3,4 @@ module AllDays import public Day1.Part1 import public Day1.Part2 import public Day2.Part1 +import public Day2.Part2 diff --git a/src/Day2/Part2.idr b/src/Day2/Part2.idr new file mode 100644 index 0000000..e9d6640 --- /dev/null +++ b/src/Day2/Part2.idr @@ -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 diff --git a/src/Main.idr b/src/Main.idr index ae2747b..85e6388 100644 --- a/src/Main.idr +++ b/src/Main.idr @@ -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)