Year2023::Day01
Part 1
picks up the first digit
picks up the last digit
forms a two-digit number
gives a final result
Part 2
picks up the first digit
picks up the last digit
forms a two-digit number
gives a final result
Results
correctly answers part 1
correctly answers part 2
Part one is solved with Regexp.
- First digit is matched with
/d/
. - Last digit requires a match and a capture
/.*(\d).*?/
. The whole string is matched, but only the last digit is captured.
Part two requires a bit more work since we also have to match words, but the principle stays the same.
A class LinePartTwo
has been made to differentiate behavior and have all tests work properly.
Year2023::Day02
Part 1
can tell if a line got too many red
can tell if a line got too many green
can tell if a line got too many blue
can tell which lines are valid
returns the game ID value
gives a final result
Part 2
returns the fewest number of red required
returns the fewest number of green required
returns the fewest number of blue required
returns the cubes power
gives a final result
Results
correctly answers part 1
correctly answers part 2
Again, we are Regexp in both parts.
For the first one, we have to make sure none of values is higher than the limits, which is pretty straight-forward.
A class LinePartTwo
has been made to differentiate behavior for part 2.
Year2023::Day03
Part 1
cleans up non-connected number parts
gives a final result
Part 2
cleans up non-connected number parts
gives a final result
Results
correctly answers part 1
correctly answers part 2
Oh boy, was that one complicated...
I'm clearly not good enough with spatial representations (something about off-by-one errors...), so I knew RIGHT AWAY that trying to map everything as [Item(X, Y, Z, number), Item(X, Y, Z, symbol)]
would be too much of an endeavor for me, but this...was though. The decision to run tests as "scenarios following the samples" instead of using proper method-based unit testing made things even worse, and sticking to the same Line
type of class as the previous days was completely stupid and shouldn't even have worked.
Maybe I'll revisit this one with a better solution.
Also, thanks to the kind people or /r/adventofcode for the sample grids they provided, they were a great help in debugging the first part properly.
Year2015::Day04
Part 1
finds winning numbers
calculates points
gives a final result
Part 2
distributes cards
gives a final result
Results
correctly answers part 1
correctly answers part 2
Part one is pretty easy. One useful method is the #&
operator that takes two arrays and returns a new one with only the matching contents. The syntax is clearly inspired by bit masking, which is a subject you should look into if you've never heard of it.
Part two is a bit more annoying and requires to do a two-pass, but nothing really improbable.