Week 6 - Advent of code. Send help.

— 2 minute read

I'm attempting Advent of Code in Rust this year. I usually don't make it far in a language I know well so this will be a challenge. My solutions live here.

  • Day 1: The functional parts of Rust are helpful. Itertools has loads of additional functionality for them, such as tuple_windows.

  • Day 2: Another opportunity for iterators. fold()ing an iterator is very similar to Array.prototype.reduce() in JavaScript.

  • Day 3: An opportunity to use bitwise operators that flew so far over my head it was barely visible. Time to read more about bit shifting and bitwise operators. The borrow checker made things difficult today.

  • Day 3: I saw a solution that used partition() to turn an iterable into two vectors based upon a function producting a boolean.

  • Day 3: BitXor (^ in Rust) is a fun opertor is you want to invert a bit based on a boolean. I went straight in with & which was the wrong thing.

  • Day 4: Vectors have a retain method which takes a boolean returning closure and removed entries in place. Really handy.

  • I went back to doing a bit of JavaScript. This is the first time I've come back and been frustrated by some aspects of the language. Do you want a for..of loop or a for..in loop? No idea, time to open DuckDuckGo again. It's a right pain.

  • Day 5: The borrow checker realised I had got it wrong before I did. I'm really enjoying using Rust and can see why it's so popular in developer surveys.

  • Day 5: If you want to iterate over a range in Rust you type something like this: 2..=4 which will give you an iterator with the values 2, 3, 4. If you want to go backwards you can't give it this: 4..=2. It won't iterate at all and you won't know why your Advent of Code solution isn't working. You need to use 2..=4.rev(). This is slightly annoying.

  • Advent of code has encouraged me to start LeetCode again. Send help.