Advent of code in Rust - solving year 2020 exercise 14 - Part 1 (Twitch Live 2021-06-28)
In this episode, we completed Advent of Code y2020 ex14 part 1 (on which we started in the previous session ➡️ https://www.youtube.com/watch?v=NcKODh5riqk).
This exercise is basically a simulation of a simple calculator that can allocate memory and apply some sort of bit-masking algorithm to change the values in memory. We needed to run a given script as input and see what was the final configuration of the memory (output).
We started with a very simple solution that wasn't particularly performant but it did work. Then we figure out how to re-implement the same solution by using AND and OR bit operations. That was quite a performance improvement.
We took the opportunity to use criterion (https://docs.rs/criterion/0.3.4/criterion/) to run benchmarks in a very effective way. It's a great library so check it out if you haven't used it already.
We also had a bunch of questions on idiomatic Rust and one of the guides that were suggested was the official Rust naming convention guide (https://rust-lang.github.io/api-guidelines/naming.html#c-conv) which also explains what all the various `into_x()`, `as_x()` and `to_x()` generally means.
We didn't start part 2 because we spent the last portion of the stream discussing a PR we received on the previous exercise (https://github.com/lmammino/rust-advent/pull/6) which was suggesting the usage of the iterator method `partition()` (https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.partition).
We ended up not merging that PR because of significant performance differences with our original implementation, although we did really like to learn about the `partition()` method.
Feel free to send us more PRs if you want to recommend us to use a different approach! We are here to learn and we'd be happy to receive more and more suggestions :)
For all the source code check out the official GitHub repo: https://github.com/lmammino/rust-advent
For seeing the next episodes live check out our Twitch channel: https://twitch.tv/loige