Expand description
§Crossed Wires
The input follow some implicit rules that can be used to simplify our approach:
- Wires cross only at right angles to each other, so we only need to consider horizontal lines when moving vertically and vice-versa.
- There is only a single vertical line at a given x coordinates and vice-versa.
This makes BTreeMap
a great choice to store horizontal or vertical line segments as there
are no collisions. The range
method can lookup all line segments contained between two
coordinates to check for intersections.
First we build two maps, one vertical and one horizontal, of each line segment for the first wire. Then we trace the steps of the second wire, looking for any intersections. We calculate both part one and part two at the same time, by also including the distance so far from the starting point of each lines.
Structs§
- Line 🔒
Functions§
Type Aliases§
- Input 🔒