Compare commits

..

No commits in common. "bf184dd8d3ce7af39b0a6850686f0a4ca81a7cb2" and "1425c6c51d7cb5b6906aa0061f9c191b4322825a" have entirely different histories.

6 changed files with 3 additions and 78 deletions

View file

@ -14,5 +14,4 @@ executable = advent-of-code-2024
main = Main
modules = Main, Utils, AllDays,
Data.Problem,
Day1.Part1, Day1.Part2,
Day2.Part1, Day2.Part2
Day1.Part1, Day1.Part2

View file

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

View file

@ -20,7 +20,7 @@ export
parseInput : String -> Maybe (List Nat, List Nat)
parseInput = map unzip . traverse parseLine . lines
--- DATA
--- UTILS
distance : Nat -> Nat -> Nat
distance x y =

View file

@ -1,43 +0,0 @@
module Day2.Part1
import Data.List
import Data.List1
import Data.String
import Utils
%default total
--- TYPES
public export
Report : Type
Report = List1 Nat
--- PARSING
parseLine : String -> Maybe Report
parseLine = traverse parseNat . split (==' ')
export
parseInput : String -> Maybe (List Report)
parseInput = traverse parseLine . lines
--- DATA
differences : Report -> List Integer
differences ns =
let is = map natToInteger ns
in zipWith (-) (tail is) (forget is)
export
isSafe : Report -> Bool
isSafe rep =
let diff = differences rep
in (all (>0) diff || all (<0) diff)
&& all ((<=3) . abs) diff
--- SOLUTION
export
solution : String -> Maybe Nat
solution inp = count isSafe <$> parseInput inp

View file

@ -1,27 +0,0 @@
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

@ -1,12 +1,10 @@
module Main
import Data.List1
import Data.Maybe
import Data.String
import Data.SortedMap
import Data.SortedMap.Dependent
import Data.Problem
import Utils
import Language.Reflection
@ -18,7 +16,7 @@ import AllDays
||| The latest problem that has been solved.
-- NOTE: UPDATE AFTER EACH SOLUTION
latest : Problem
latest = Pr 2 Part2
latest = Pr 1 Part2
solMap : SortedMap Problem (String -> String)