Advent of Code 2019 - Day 3

My solution.

3 Likes

I like the intensive usage of streams :slight_smile:

hereā€™s mine

1 Like

Interesting solution. I like the idea of putting all points in two MapSets, the code is pretty straightforward to read.

1 Like

My solution

Funny you say that, I did actually say to myself when I sat down that I wanted to try your technique of stream-all-the-things today. In the end though, I didnā€™t feel like I fit it to the problem very well. :slight_smile:

I rarely bother to explain my solutions because I post them so late in the cycle that my ideas are already represented. I do read through the solutions of others when Iā€™m done though.

1 Like

I ended up switching datastructure two times for day 3. Started with lists for the wires, but switched to MapSet to be able to use MapSet.intersection/2. Then for part 2 I switched to Map to be able to track steps, but continued comparing using MapSet.intersection by first converting to a MapSet.

My solution is a bit overkill with nested modules to contain different parts of the code, itā€™s something Iā€™ve experimented with recently, to see if the code stays more readable when I return to it later. Though I didnā€™t go all the way through with it. Code left it as it was when I finished part 2.

Yeah, it doesnā€™t seem that streams are optimal here. To be clear, I donā€™t use streams that much in real code, but I like to use these challenges to practice them a bit.

Escripts are slow and my initial solution with maps was very slow so I re-wrote my Gleam solution after watching this: https://github.com/michallepicki/adventofcode/blob/master/2019/gleam/src/crossed_wires_after_watching_freds_recording.gleam

(could optimize even further but meh)

Iā€™m slowly catching up!

1 Like

Finally solved Day03 after tracking down a silly logic error which didnā€™t show up in any of the tests but did when I was trying to calculate my part 2 result. Code is here.