Note by the Moderators: This topic is to talk about Day 4 of the Advent of Code.
For general discussion about the Advent of Code 2018 and links to topics of the other days, see this topic.
Day 4 is in the bag after a bit of a struggle.
For part 1 I had two minutes which has the same count of times asleep for a guard and typically (well, maybe fortunately) my code returned the second minute value which was rejected. I changed my code to look for the earliest minute with the maximum count and all was well.
Part 2 was all down to me and a stupid code mistake but my test using the sample data was passing which threw me off for a while (the same problem happened with part 1). I should probably add my own test data in so that my tests are more comprehensive.
My code was more structured today (I’m using more functions and also a couple of structs) but I’ve still got some Enum.reduce/3
calls in my pipelines which I need to move into their own functions.
And for variety, unlike using regex to parse the data strings which I did yesterday, today I used String.slice/2
.
Still need to document things properly however.
Code is at https://github.com/simon-wolf/advent-of-code-2018/blob/master/lib/advent_of_code_2018/day_04.ex