Commit 04cc980 1 parent 8457172 commit 04cc980 Copy full SHA for 04cc980
File tree 3 files changed +4
-11
lines changed
3 files changed +4
-11
lines changed Original file line number Diff line number Diff line change @@ -8,10 +8,12 @@ private def decorateWithCoordinates (s: String): List PointAndChar := do
8
8
let (x, c) <- line.toList.enum
9
9
pure ⟨⟨x, y⟩, c⟩
10
10
11
+ private def removeDots (decoratedChars : List PointAndChar) : List PointAndChar := decoratedChars.filter (·.char != '.' )
12
+
11
13
def parseInput (s : String): PuzzleInput :=
12
14
let decoratedChars := decorateWithCoordinates s
13
15
let (xs, ys) := decoratedChars.map (·.point.toPair) |>.unzip
14
16
let width := xs.max?.map (· + 1 |>.toNat) |>.getD 0
15
17
let height := ys.max?.map (· + 1 |>.toNat) |>.getD 0
16
18
let bounds: Rectangle := { topLeft := Point.origin, width, height }
17
- { bounds, decoratedChars }
19
+ { bounds, decoratedChars := removeDots decoratedChars }
Original file line number Diff line number Diff line change @@ -7,10 +7,8 @@ open Std (HashMap)
7
7
8
8
-- Part 1
9
9
10
- private def removeDots (decoratedChars : List PointAndChar) : List PointAndChar := decoratedChars.filter (·.char != '.' )
11
-
12
10
private def getAntennaeGroups (input : PuzzleInput) : List (List Point) :=
13
- input.decoratedChars |> removeDots |> .groupByAndTransformValues (·.char) (·.point) |>.values
11
+ input.decoratedChars |>.groupByAndTransformValues (·.char) (·.point) |>.values
14
12
15
13
private def findAntinodes (antennaGroup : List Point) : List Point := do
16
14
let antenna1 <- antennaGroup
Original file line number Diff line number Diff line change @@ -28,13 +28,6 @@ instance [BEq α] [BEq β] : BEq (Except α β) where
28
28
| Except.error x, Except.error y => x == y
29
29
| _, _ => false
30
30
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
-
38
31
def sepBy (p : Parser α) (sep : Parser β) : Parser (List α) :=
39
32
(do
40
33
let x ← p
You can’t perform that action at this time.
0 commit comments