partition and inject intersection &:& 👯♂️ - Day 13 - Advent of Code 2023
Вставка
- Опубліковано 26 сер 2024
- In this episode, we solve day 13 of Advent of Code 2023, called "Point of Incidence", where we're trying to find lines of symmetry in patterns of dots and pound signs representing mirrors on Lava Island.
First, we parse the input into arrays of character arrays representing each pattern. Then we write some methods to check if a line is symmetrical around a given point, find all points of symmetry on a line, and ultimately find lines of symmetry in a full pattern.
The key is finding the intersection of symmetry points across all lines to pinpoint the overall symmetry. We handle both horizontal and vertical lines of symmetry.
For part 1, we report the number of rows above or columns left of the symmetry lines.
For part 2, we consider smudges - swapping one character in the pattern and rechecking for other valid lines of symmetry. We brute force check all possibilities, collect the new lines, and subtract out ones we already had.
In the end, we arrive at working solutions for both parts, matching the provided examples.
Advent of Code: adventofcode.com/
My Solutions: gist.github.co...
Playlist • Advent of Code
#adventofcode #ruby
You are truly a brilliant teacher, my dude.
Thanks, Mike!
OK. After lots of work finally, I managed to solve 1st puzzle of day 13th by counting same rows:
same_rows = Hash.new([])
pattern.each_with_index{|row,i| same_rows[row] += [i] }
Oh, your brute force method was nice. I have to remember that sometimes simply methods are right ones.