feat: part 2-2
This commit is contained in:
parent
fad1b50858
commit
bf184dd8d3
|
@ -15,4 +15,4 @@ main = Main
|
|||
modules = Main, Utils, AllDays,
|
||||
Data.Problem,
|
||||
Day1.Part1, Day1.Part2,
|
||||
Day2.Part1
|
||||
Day2.Part1, Day2.Part2
|
||||
|
|
|
@ -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
27
src/Day2/Part2.idr
Normal 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
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue