Advent of code in Rust - solving year 2020 exercise 13 - Part 1 (Twitch Live 2021-06-14)
In this episode, we completed Advent of Code y2020 ex13 part 1 and did some good progress on part 2 as well.
In this exercise, we needed to figure out which bus to take by doing some interesting math.
We implemented a brute force solution for part 2 but it is not fast enough, so we'll need to figure out a more efficient approach to it.
Thanks to all our watchers for the great suggestions. We did learn a few interesting things:
- Use `filter_map()` with iterators (rather than a chain with a `filter()` and a `map()`): https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.filter_map
- Use `map()` to convert values inside `Result` types: https://doc.rust-lang.org/std/result/enum.Result.html#method.map
- `map()` works on Option too! https://doc.rust-lang.org/std/option/enum.Option.html#method.map
- `max_by_key()` is another convenient function that can be used to extract a max value from a `Vec` of complex types using some arbitrary max logic item by item (no comparison function needed): https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.max_by_key
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