Advent of Code 2021 in Ruby Getting Started & Day 1

Baldomero Vela III
3 min readFeb 10, 2022

Well I’m a little late to the Advent of Code party, had all sorts of COVID related issues including a case of it myself. But here we are. A friend of mine had told me about early in December, shortly after I graduated from Flatiron in November. Long story short Advent of Code is a annual series of programing challenges written by Eric Wastl (really dig their personal site’s styling btw.) The problems are quite fun, and can be solved in any programing language.

https://github.com/search?q=advent+of+code

Judging from the GitHub search results, there were thousands of other programmers that have already tried their hand at it. Take Sebastian Aigner and other developers at Jetbrains for example. They have a few posts about using Kotlin, but I elected to try my hand at polishing my knowledge of Ruby.

Take a gander at my solutions on my GitHub Repo. At the time of writing this intro, I’m still cracking my way through.

A few pedantic notes about my IDE (integrated development environment), I’m using Ruby 3.0.0p0 on Windows Subsystem for Linux 2 using the Ubuntu 20.04 LTS distro.

Day 1: Sonar Sweep

Okay spoiler warning from here on out!

Santa has a brand new submarine.

Santa Claus has new submarine, and we’re gonna need it. However it looks like we’re gonna have to write an entire command and control suit to interface with it’s electronics.

Right out of the gate we’re asked to keep track of the submersible’s sonar telemetry. Our sample data below is an example of what to expect from our puzzle input.

Now our first task is to count the number of times the depth measurement is increasing versus the previous measurement. So lets’s get to it. First let’s make a directory to hold our solutions with mkdir AOC21 in the command line. We’ll throw open a Visual Studio Code (VSC) inside this directory. Next I made a sub-folder for Day 1 and used touch depth.rb to hold my first solution. Later, we can execute the file and it’s script by typing ruby depth.rb But, for now lets actually get some coding done. Lets define a function that we can call to be run to execute our program. In this case we’ll call it depth, and we have to call the function to be executed after it’s defined. Lets also have our function log a short message to the terminal window to let us know it’s been invoked.

--

--