Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
mdr committed Dec 1, 2024
1 parent f5db3fb commit 41312f5
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Aoc2024/Day01/Solve.lean
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ private def solvePart1 (pairs : List (Int × Int)) : Int :=
let distance (a b : Int) : Int := (a - b).natAbs
(firsts.mergeSort.zipWith distance seconds.mergeSort).sum

def parseAndSolvePart1 (s : String): Except String Int := parseLines s |> .map solvePart1
def parseAndSolvePart1 (s : String): Except String Int := parseLines s |>.map solvePart1

#guard (parseAndSolvePart1 exampleInput == Except.ok 11)
#guard parseAndSolvePart1 exampleInput == Except.ok 11

private def solvePart2 (pairs : List (Int × Int)) : Int :=
let (firsts, seconds) := pairs.unzip
let similarityScore (n : Int) : Int := seconds.count n * n
firsts.sumBy similarityScore

def parseAndSolvePart2 (s : String): Except String Int := parseLines s |> .map solvePart2
def parseAndSolvePart2 (s : String): Except String Int := parseLines s |>.map solvePart2

#guard (parseAndSolvePart2 exampleInput == Except.ok 31)
#guard parseAndSolvePart2 exampleInput == Except.ok 31

0 comments on commit 41312f5

Please sign in to comment.