Back to Blog

Solving Advent of Code Puzzles with Shoreline

Using Shoreline's Oplang and Metrics System to Solve Advent of Code Puzzles

Advent of code is a popular programming challenge with two puzzles a day from December 1st through 25th. People often use it as a way to try a new programming language, use languages they are already familiar with in new and interesting ways, or just as a fun challenge. Since the first day's two puzzles both involve time series data, it was a good opportunity to use Shoreline's Op language and metrics system to write the data and solve the puzzle.

First, we'll use Shoreline's statsd endpoint to write the data used in the puzzle, so that it can be ingested by Shoreline's metric system. Grabbing the data from the link above, their example uses:

Now, we'll use a Shoreline action to install netcat on our shoreline pods for use with statsd

Next, we'll define a custom action to write the data:

And a custom metric query to read the above data:

Now that we have an action write our data, we'll use a short bash script that uses Shoreline's CLI to write the test data:

After the data has been written, we can run a metric query that uses the puzzle_data metric defined above to verify that we have the right numbers:


Now, we're ready to solve the two puzzles.

Part 1 asks for the number of times the sequence increases. So, we can use an irate to compute the consecutive differences, check which of the differences are greater than 0 (giving 1 if this is the case and 0 if not), and then pipe this into a sum to get the total number of positive differences (7):

Part 2 is similar, but asks us to compute the sliding sum with a window size of 3 increases, rather than just consecutive values. So, we'll add a sum(3, "SLIDING") to our previous solution to get our answer of 5: