Skip to main content

Advent of Code 2021 Recap

· 2 min read

2021 is now over and I have completed the advent of code in Rust. Here are my findings.

Rust

Rust has its quirks when writing the code, but the error messages are very clear.

Having worked in other pointer/reference handling languages (C++ mainly), it was pretty easy to pick up.

As I was expecting, performance is absolutely incredible as well.

Making trees and graphs is pretty complicated though. Since Rust does a lot of checks on variable lifetimes and borrows as well as stack size, you can't easily have pointers to nodes within a node structure. Most of the problems I ended up a pattern that seems to be called a "memory arena" by the Rust community. In this pattern you keep a list of all the nodes, usually in a vector for instant random access, and each node contains the index of other nodes it's referring to instead of a pointer to it. If the tree/graph doesn't change, it's pretty easy to use, but if you need to modify it, it becomes a little more complicated although doable.

Problems were overall good

Most of the problems were pretty easy to solve algorithmically. Some problems took me more time as I mentioned above because I'm not used to creating trees and graphs in Rust. Another notable mention is problem 24 which is a little more complicated to solve and takes a lot of experimentations before you can figure out how you're supposed to reduce the search space. I wished they didn't put that as the last problem.

What I missed the most out of all the problems compared to previous years was a set a problem to made you evolve a previous solution. This was usually done as a assembly-like language you had to write a computer emulator for. I hope they bring something similar back in future years.

Final thoughts

Overall very fun and Rust was a blast to use.

All my code and inputs are available in advent2021 for those interested.