each_cons, and layers 🎂 - Day 09 - Advent of Code 2023

Learn how to solve Day 9 of Advent of Code 2023 - Mirage Maintenance - in Ruby!

In this episode, we'll cover:
Parsing the input data into statistics
Breaking down the statistics layer by layer to differences
Building back up each layer to extrapolate the next value
Collecting layers into an array of arrays
Predicting future and past values by adding to array ends
Refactoring with destructuring for conciseness

The solution demonstrates some neat iteration techniques in Ruby:
each_cons to yield consecutive pairs
unshift to add to array front
map, select, inject to transform arrays

We walk through the thought process, test examples, and refine the logic until we have scripts that generate the right answers for both parts of this puzzle.


If you're participating in Advent of Code or just want to level up your Ruby skills, join me for this festive programming challenge!

Advent of Code: https://adventofcode.com/
My Solutions: https://gist.github.com/cjavdev/d15a2a4ffed6c840c2fb28a093e9f927/
Playlist https://www.youtube.com/playlist?list=PLS6F722u-R6KYlGyUv65EFpGKl2Esmurr

#adventofcode #ruby