Advent of Code 2022 in Rust
The major things I've learned from doing the Advent of Code (AoC) 2022 in Rust is
- I'm bad at backtracking, and
- I have the reading comprehension of a 3 year old.
Day 16--Proboscidea Volcanium, releasing pressure by opening valves--was the main day that I struggled with. Other days had off by one errors, or a bit of rethinking on strategy to solve, but were solved with some debugging.
The volcano beat me. I could not think of effective backtracking strategies, and got lost at how to incorporate the elephant's movements in part 2. With a bit of help from the subreddit I finally got through it.
This experience did prepare me a little for day 19, building geode cracking robots. I again had to use some pruning strategies I found on the subreddit to beat it.
Actually using Rust for these problems was great. Enums ability to store extra data is something I miss in every other language I use. Rust raising panics on integer overflows in debug mode was particularly useful for finding mistakes. Some AoC problems, if done wrong, cause you to end up with numbers beyond any primitive integer type. In previous years with other languages, this has caused a lot of confusion because implicit wrapping hides the issue.
With all of the graphs and trees used in AoC, I expected to have more issues
dealing with ownership than I did. I think part of the reason this was not be
case was due to the tree nodes being very small, and therefore it being
acceptable to be Clone
and Copy
in some cases.
It is something I see in a lot of people getting started in Rust. They assume
that every .clone()
is evil, and every .unwrap()
will bring wrath upon them.
AoC involves a lot of parsing of input, and liberally unwrapping speeds up the
process considerably.
What's Christmas without a bunch of .unwrap()
ing anyway?