3rd week of Advent of Code '22 in Rust
Let's go through the third week of Advent of Code in Rust.
Day 15: Beacon Exclusion Zone
Triangulating a distress beacon based on the information from the sensors.
Solution
Relatively easy thing to implement, no major Rust issues hit.
Day 16: Proboscidea Volcanium
Finding a max flow in a graph given some time constraints.
Solution
I have used some interesting things to implement this and make it easier for me.
Indexing in graph
I have come across a situation where I needed to keep more information regarding the graph… In that case you can, of course, create a structure and keep it in, but once you have multiple members in the structure it gets harder to work with since you need to address the fields in the structure. When you work with graph, you frequently need to access the vertices and in this case it felt a lot easier to implement the indexing in a graph, rather than explicitly access the underlying data structure.
Here you can see a rather short snippet from the solution that allows you to “index” the graph:
impl Index<&str> for Graph {
type Output = Vertex;
fn index(&self, index: &str) -> &Self::Output {
&self.g[index]
}
}
