transpose, reverse, roll! - Day 14 - Advent of Code 2023
Вставка
- Опубліковано 26 сер 2024
- In this video, you’ll see how to solve Day 14 for the Advent of Code 2023 Part 1 and Part 2. The puzzle involves manipulating a grid representing a panel with rocks on it. The goal is to tilt the panel north, south, east and west to get the round rocks to roll around.
In Part 1, we’ll write a "roll" method to move the round rocks on a single row all the way to the left by swapping spaces. Then we’ll use "transpose" to tilt the whole grid north and calculate the "weight" or load on the north beam.
In Part 2, the puzzle introduces a "spin cycle" which tilts the panel in four directions repeatedly. We’ll write methods for tilting each direction. Then detect cycles in the grid states using a dictionary and set to count unique patterns. By moduloing the number of cycles by the cycle length, we’re able to index into the grid states and get the weight after 1 billion cycles.
The video demonstrates Ruby array manipulation, recursion, cycles and modulo to solve the Advent of Code puzzle.
Advent of Code: adventofcode.com/
My Solutions: gist.github.co...
Playlist • Advent of Code
#adventofcode #ruby - Навчання та стиль
That recursive swap is probably the simplest way I have seen, nice job
Kinda like bubble sort