Sean Handley
Dec 3, 2022

--

Hey Ashley

Found this via the reddit megathread - nice write-up.

As you asked, here's what I did with Ruby:

https://github.com/seanhandley/adventofcode2022/blob/main/ruby/day_3/advent3.1.rb

https://github.com/seanhandley/adventofcode2022/blob/main/ruby/day_3/advent3.2.rb

The real hero here is the `reduce` method, allowing the main code to work with groups of two and three interchangeably.

Also, `each_slice` makes it very easy to split the input into compartments.

I also write my solutions as executable Ruby files and I run them by piping the puzzle input via STDIN, as per Unix design principles.

I like the solution overall because it's in more of a functional style than imperative.

--

--

Sean Handley
Sean Handley

Written by Sean Handley

Engineer, leader, open-source fan.

Responses (1)