Skip to content

Commit 04cc980

Browse files
committed
move to parser
1 parent 8457172 commit 04cc980

File tree

3 files changed

+4
-11
lines changed

3 files changed

+4
-11
lines changed

Aoc2024/Day08/Parser.lean

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ private def decorateWithCoordinates (s: String): List PointAndChar := do
88
let (x, c) <- line.toList.enum
99
pure ⟨⟨x, y⟩, c⟩
1010

11+
private def removeDots (decoratedChars : List PointAndChar) : List PointAndChar := decoratedChars.filter (·.char != '.')
12+
1113
def parseInput (s : String): PuzzleInput :=
1214
let decoratedChars := decorateWithCoordinates s
1315
let (xs, ys) := decoratedChars.map (·.point.toPair) |>.unzip
1416
let width := xs.max?.map (· + 1 |>.toNat) |>.getD 0
1517
let height := ys.max?.map (· + 1 |>.toNat) |>.getD 0
1618
let bounds: Rectangle := { topLeft := Point.origin, width, height }
17-
{ bounds, decoratedChars }
19+
{ bounds, decoratedChars := removeDots decoratedChars }

Aoc2024/Day08/Solve.lean

+1-3
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@ open Std (HashMap)
77

88
-- Part 1
99

10-
private def removeDots (decoratedChars : List PointAndChar) : List PointAndChar := decoratedChars.filter (·.char != '.')
11-
1210
private def getAntennaeGroups (input : PuzzleInput) : List (List Point) :=
13-
input.decoratedChars |> removeDots |>.groupByAndTransformValues (·.char) (·.point) |>.values
11+
input.decoratedChars |>.groupByAndTransformValues (·.char) (·.point) |>.values
1412

1513
private def findAntinodes (antennaGroup : List Point) : List Point := do
1614
let antenna1 <- antennaGroup

Aoc2024/Utils.lean

-7
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,6 @@ instance [BEq α] [BEq β] : BEq (Except α β) where
2828
| Except.error x, Except.error y => x == y
2929
| _, _ => false
3030

31-
def getOrThrow (message : String) : Option α -> Except String α
32-
| some x => pure x
33-
| none => throw message
34-
35-
#guard (getOrThrow "Error" (some 42) == Except.ok 42)
36-
#guard (getOrThrow "Error" (none : Option Int) == Except.error "Error")
37-
3831
def sepBy (p : Parser α) (sep : Parser β) : Parser (List α) :=
3932
(do
4033
let x ← p

0 commit comments

Comments
 (0)