🎄 This year I'm starting out with using it to learn Rust from scratch, so let's see how long it takes until I switch back to trusted old Python.
- Solution. An easy start this year, which gave me a good opportunity to learn about
Vec
andHashMap
data structures in Rust. I really like theOption<T>
enum approach to handling optional values. - Solution. This one made me learn about cloning vectors, how to turn vectors into iterators, and anonymous functions. I got a bit stuck at first, as I was including 0 as an acceptable value when checking for the gradient monotony. Luckily writing some tests for my gradient monotony function got me to figure that out quickly!
- Learnt about the
Vec::windows
method, that returns an iterator over a window of given size. So you can just.map
over it using an anonymous diff function to calculate the gradient array.
- Learnt about the
- Solution. Simple regex parsing. This time I learned more about how to implement functions that return an
Option<T>
. Combined with the?
shorthand for propagating errors, this makes for really nice happy-path coding without the verbosity that you see in Go code. - Solution. Nice! I liked that I could just use the count of a given page number in the valid rulesets to determine the ordering! At first I thought I'd need to iterate a lot more.
- Solution. Had fun over-engineering this by implementing a
Vec2d
struct, that represents a 2D vector as a 1D vector. First time I did OOP in Rust, so lots of things to learn here. Haven't started on Part 2 yet, though. - Solution. I got a bit annoyed here with Rust, as creating the cartesian product of operators felt like an unneccessary hassle to get Rust to do what I wanted it to do. A stark contrast to Python's
itertools
. Also first time in my life I had to deal with an integer overflow, because I was using firsti32
for the calculations, but it requiredi64
. Thankfully Rust just tells you that when trying to parse a stringified number.