summaryrefslogtreecommitdiff
path: root/Day10.lean
diff options
context:
space:
mode:
authorAndreas Grois <andi@grois.info>2024-09-08 22:21:23 +0200
committerAndreas Grois <andi@grois.info>2024-09-08 22:21:23 +0200
commit7e50958adb75487cef49807b1a515591544cf6ac (patch)
tree77b9d460680af1691f05d2d4440d1e6ba167196b /Day10.lean
parent67d0b0c8fa307308e8a96ce4566821aa8260ef73 (diff)
Begin Day 10 Part 2
Diffstat (limited to 'Day10.lean')
-rw-r--r--Day10.lean49
1 files changed, 38 insertions, 11 deletions
diff --git a/Day10.lean b/Day10.lean
index 5bc283e..8191f55 100644
--- a/Day10.lean
+++ b/Day10.lean
@@ -1,4 +1,5 @@
import «Common»
+import «BinaryHeap»
namespace Day10
@@ -946,18 +947,21 @@ private def Area.nextPathStep (last_step: Area.PathHead area) : Option (Area.Bid
none
end
+private def Area.pathStarts (area : Area) : List (Area.PathHead area) :=
+ [area.start.goNorth, area.start.goEast, area.start.goSouth, area.start.goWest]
+ |> .filterMap λ c ↦ c.bind λc ↦
+ if h: area.can_connect_to c area.start then
+ some {
+ current := c
+ previous := area.start
+ current_can_connect_to_previous := h
+ }
+ else
+ none
+
+
def part1 (area : Area) : Option Nat := do
- let mut paths : List (Area.PathHead area) :=
- [area.start.goNorth, area.start.goEast, area.start.goSouth, area.start.goWest]
- |> .filterMap λ c ↦ c.bind λc ↦
- if h: area.can_connect_to c area.start then
- some {
- current := c
- previous := area.start
- current_can_connect_to_previous := h
- }
- else
- none
+ let mut paths : List (Area.PathHead area) := area.pathStarts
let mut steps := 1
-- The condition in the while-loop is not needed. The program always terminates, as the
@@ -986,6 +990,29 @@ where
| _ => false
------------------------------------------------------------------------------------------------------------
+
+private def coordinateSorter (a b : Coordinate w h) : Bool :=
+ a.y < b.y ∨ (a.y = b.y ∧ a.x ≤ b.x)
+
+private theorem coordiateSorter_transitive {w h : Nat} : BinaryHeap.transitive_le (coordinateSorter (w := w) (h := h)) := by
+ unfold BinaryHeap.transitive_le
+ intros a b c
+ unfold coordinateSorter
+ simp
+ omega
+
+private theorem coordinateSorter_total {w h : Nat} : BinaryHeap.total_le (coordinateSorter (w := w) (h := h)) := by
+ unfold BinaryHeap.total_le
+ intros a b
+ unfold coordinateSorter
+ simp
+ omega
+
+def part2 (area : Area) : Option Nat :=
+ sorry
+
+
+------------------------------------------------------------------------------------------------------------
open DayPart
instance : Parse ⟨10, by simp⟩ (ι := Area) where
parse := Except.mapError toString ∘ Area.parse