Live streamed Learning Rust by solving Advent of Code
Advent of code in Rust - solving day 5/2021 (Twitch Live 2022-02-07)
https://www.youtube.com/watch?v=vjCzBekLRdY
In this episode, we completed day 5 of Advent of Code y2021 using Rust!
In today's challenge we needed to represent overlapping segments over a two dimensional space and count home many overlapping points we would find.
The first part of the exercise required us to look only for vertical and horizontal segments, while in the second part we had also diagonal segments with an angle of 45 degrees.
We decided to go for a generalised solution using a custom iterator that allows us to iterate over all the discrete points of a segment.
We can build the iterator from a segment and it will be able to figure out all the discrete points from point1 to point2 and allow us to iterate over them.
We did all of this with a custom SegmentIterator struct which implements the Iterator Trait: https://doc.rust-lang.org/std/iter/tr...
This made our solution quite simple.
At the end of the stream we also managed to generalise the code for part1 and part2 by creating a couple of helper methods using trait objects (so that we can deal with generic iterators producing 2D points).
If you have any suggestion, we'd love to hear it, so please leave a comment or a create a PR!
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