Advent of Code 2026: Day 01
It's that time of year again, when I get excited about a programming advent calendar, and then forget about it later in December! Though, this year, there are only a handful of puzzles, so I feel like it should be achievable to do them all this time!
So without further ado, here is Day 1.
A nice and easy start, that saw me taking longer that I expected to remember some Ruby APIs that I didn't use as often!
Part 1:
We were asked to find the 3 most common items in a list, then multiply them together to come up with an answer.
input.tally.sort_by { |k,v| v }.reverse.first(3).flat_map{|p| Integer(p[0]) }.inject(:*)⭐️ A fairly simple solution — tally all the items, sort them by the number of times they appear, then multiply.
Part 2:
Oh no, we actually needed the 3 least common items in the list:
input.tally.sort_by { |k,v| v }.first(3).flat_map{|p| Integer(p[0]) }.inject(:*)⭐️ Pretty much the same as the first one, but leaving the list in ascending order of popularity, and taking the first 3 items before multiplying them.