Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
mdr committed Dec 2, 2024
1 parent fdd21b6 commit 49ceed2
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Aoc2024/Day02/Solve.lean
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ def parseAndSolvePart1 (s : String): Except String Int := parseReports s |>.map
private def isSafeWithTolerance (report : Report) : Bool :=
List.range report.length |>.map report.removeNth |>.any isSafe

#guard isSafeWithTolerance [7, 6, 4, 2, 1] == true
#guard isSafeWithTolerance [1, 2, 7, 8, 9] == false
#guard isSafeWithTolerance [9, 7, 6, 2, 1] == false
#guard isSafeWithTolerance [1, 3, 2, 4, 5] == true
#guard isSafeWithTolerance [8, 6, 4, 4, 1] == true
#guard isSafeWithTolerance [1, 3, 6, 7, 9] == true

private def solvePart2 (reports : List Report) : Int := reports.countP isSafeWithTolerance

def parseAndSolvePart2 (s : String): Except String Int := parseReports s |>.map solvePart2
Expand Down

0 comments on commit 49ceed2

Please sign in to comment.