Skip to content

Commit 5d02aaa

Browse files
committed
wip
1 parent fbfc13d commit 5d02aaa

File tree

3 files changed

+42
-63
lines changed

3 files changed

+42
-63
lines changed

Aoc2024/Day06/Types.lean

+1-22
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
import Std
2+
import Aoc2024.Utils
23
open Std (HashSet)
34

4-
structure Point where
5-
x : Int
6-
y : Int
7-
deriving BEq, Hashable, Repr, Inhabited
8-
9-
def Point.toPair (p : Point) : (Int × Int) := (p.x, p.y)
10-
115
inductive Direction where
126
| Up
137
| Right
@@ -28,21 +22,6 @@ def Point.step (p : Point) (d : Direction) : Point :=
2822
| Direction.Down => { p with y := p.y + 1 }
2923
| Direction.Left => { p with x := p.x - 1 }
3024

31-
def Point.origin : Point := { x := 0, y := 0 }
32-
33-
structure Rectangle where
34-
topLeft : Point
35-
width: Nat
36-
height: Nat
37-
deriving Repr, BEq, Hashable, Inhabited
38-
39-
def Rectangle.contains (r : Rectangle) (p : Point) : Bool :=
40-
r.topLeft.x ≤ p.x && p.x < r.topLeft.x + r.width &&
41-
r.topLeft.y ≤ p.y && p.y < r.topLeft.y + r.height
42-
43-
#guard Rectangle.contains { topLeft := Point.origin, width := 2, height := 2 } { x := 1, y := 1 }
44-
#guard !Rectangle.contains { topLeft := Point.origin, width := 2, height := 2 } { x := 2, y := 2 }
45-
4625
structure PuzzleInput where
4726
obstacles : HashSet Point
4827
bounds : Rectangle

Aoc2024/Day08/Types.lean

-41
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,6 @@ import Aoc2024.Utils
22
import Std
33
open Std (HashSet)
44

5-
structure Point where
6-
x : Int
7-
y : Int
8-
deriving BEq, Hashable, Repr, Inhabited
9-
10-
def Point.toPair (p : Point) : (Int × Int) := (p.x, p.y)
11-
12-
def Point.origin : Point := { x := 0, y := 0 }
13-
14-
structure Vector where
15-
x : Int
16-
y : Int
17-
deriving BEq, Hashable, Repr, Inhabited
18-
19-
def Point.vectorTo (from_ to : Point) : Vector := { x := to.x - from_.x, y := to.y - from_.y }
20-
#guard ({ x := 1, y := 1 } : Point).vectorTo { x := 2, y := 2 } == { x := 1, y := 1 }
21-
22-
def Point.add (p : Point) (v : Vector) : Point := { x := p.x + v.x, y := p.y + v.y }
23-
#guard Point.add { x := 1, y := 1 } { x := 2, y := 2 } == { x := 3, y := 3 }
24-
25-
structure Rectangle where
26-
topLeft : Point
27-
width: Nat
28-
height: Nat
29-
deriving Repr, BEq, Hashable, Inhabited
30-
31-
def Rectangle.contains (r : Rectangle) (p : Point) : Bool :=
32-
r.topLeft.x ≤ p.x && p.x < r.topLeft.x + r.width &&
33-
r.topLeft.y ≤ p.y && p.y < r.topLeft.y + r.height
34-
35-
#guard Rectangle.contains { topLeft := Point.origin, width := 2, height := 2 } { x := 1, y := 1 }
36-
#guard !Rectangle.contains { topLeft := Point.origin, width := 2, height := 2 } { x := 2, y := 2 }
37-
38-
def Rectangle.allPoints (r : Rectangle) : List Point := do
39-
let x <- intRange r.topLeft.x (r.topLeft.x + r.width)
40-
let y <- intRange r.topLeft.y (r.topLeft.y + r.height)
41-
return { x := x, y := y }
42-
43-
#guard Rectangle.allPoints { topLeft := Point.origin, width := 2, height := 2 } ==
44-
[{ x := 0, y := 0 }, { x := 0, y := 1 }, { x := 1, y := 0 }, { x := 1, y := 1 }]
45-
465
structure PointAndChar where
476
point: Point
487
char: Char

Aoc2024/Utils.lean

+41
Original file line numberDiff line numberDiff line change
@@ -225,3 +225,44 @@ def intRange (m n : Int) : List Int :=
225225
#guard intRange 1 1 == []
226226

227227
instance hashableChar: Hashable Char where hash c := c.toNat |> hash
228+
229+
structure Point where
230+
x : Int
231+
y : Int
232+
deriving BEq, Hashable, Repr, Inhabited
233+
234+
def Point.toPair (p : Point) : (Int × Int) := (p.x, p.y)
235+
236+
def Point.origin : Point := { x := 0, y := 0 }
237+
238+
structure Vector where
239+
x : Int
240+
y : Int
241+
deriving BEq, Hashable, Repr, Inhabited
242+
243+
def Point.vectorTo (from_ to : Point) : Vector := { x := to.x - from_.x, y := to.y - from_.y }
244+
#guard ({ x := 1, y := 1 } : Point).vectorTo { x := 2, y := 2 } == { x := 1, y := 1 }
245+
246+
def Point.add (p : Point) (v : Vector) : Point := { x := p.x + v.x, y := p.y + v.y }
247+
#guard Point.add { x := 1, y := 1 } { x := 2, y := 2 } == { x := 3, y := 3 }
248+
249+
structure Rectangle where
250+
topLeft : Point
251+
width: Nat
252+
height: Nat
253+
deriving Repr, BEq, Hashable, Inhabited
254+
255+
def Rectangle.contains (r : Rectangle) (p : Point) : Bool :=
256+
r.topLeft.x ≤ p.x && p.x < r.topLeft.x + r.width &&
257+
r.topLeft.y ≤ p.y && p.y < r.topLeft.y + r.height
258+
259+
#guard Rectangle.contains { topLeft := Point.origin, width := 2, height := 2 } { x := 1, y := 1 }
260+
#guard !Rectangle.contains { topLeft := Point.origin, width := 2, height := 2 } { x := 2, y := 2 }
261+
262+
def Rectangle.allPoints (r : Rectangle) : List Point := do
263+
let x <- intRange r.topLeft.x (r.topLeft.x + r.width)
264+
let y <- intRange r.topLeft.y (r.topLeft.y + r.height)
265+
return { x := x, y := y }
266+
267+
#guard Rectangle.allPoints { topLeft := Point.origin, width := 2, height := 2 } ==
268+
[{ x := 0, y := 0 }, { x := 0, y := 1 }, { x := 1, y := 0 }, { x := 1, y := 1 }]

0 commit comments

Comments
 (0)