Advent of Code 2025 in Lean 4 – Day 8
hamberg.no·1d
🦀Rust Macros
Preview
Report Post

Today’s problem was all about connected components where the nodes were 3D positions, so the first thing I did was to define a data structure for 3D positions:

structure Position3D where
x : Int
y : Int
z : Int

To avoid leaving the beautiful, simple world of integers, I defined a method for computing the square distance between positions, hoping that I wouldn’t need to find the actual distances:

def Position3D.squaredDistance (p1 p2 : Position3D) : Int :=
(p1.x - p2.x)^2 + (p1.y - p2.y)^2 + (p1.z - p2.z)^2

I then parsed each position and was on my merry way. The first thing I did was to build an array with each pair of positions and their squared distance, sorted by that distance. I then created a list of HashSets to repr…

Similar Posts

Loading similar posts...