13
π - 2023 DAY 13 SOLUTIONS -π
(programming.dev)
An unofficial home for the advent of code community on programming.dev!
Advent of Code is an annual Advent calendar of small programming puzzles for a variety of skill sets and skill levels that can be solved in any programming language you like.
Solution Threads
M | T | W | T | F | S | S |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 |
Icon base by Lorc under CC BY 3.0 with modifications to add a gradient
console.log('Hello World')
Wouldn't this code fail in a case like this? Because you count different lines, not different characters in the lines, right? Or am I missing something? Thanks (Let's ignore column symmetry for the sake of example).
(I think you will get answer 100, but the answer is 300)
But for sure after seeing this I have to learn Scala.
On your example, my code produces 301, which matches your 300 ignoring column symmetry (and 0 for task2, as there is no way to smudge a single cell to create symmetry).
Let me explain the code real quick: What
smudgesAround
does is compute the number of tiles you would need to change to create a symmetry around indexi
. First,toEdge
is the number of tiles to the nearest edge, everything after that will be reflected outside the grid and won't matter. Then, for each actually relevant distance, we compare the rows/columns this distance fromi
. By zipping them, we create an Iterator that first yields the pair of first entries, then the pair of second entries, and so on. On each pair we apply a comparison, to count the number of entries which did not match. This is the number of smudges we need to fix to get these rows/columns to match. Summing over all relevant pairs of rows/columns, we get the total number of smudges to makei
a mirror line. In symmetries, we just check eachi
, for task1 we want a mirror line without smudges and for task2 we want a mirror line for exactly oneYou can also make this quite a bit shorter, if you want to sacrifice some more readability:
Oh, I see, I for some reason switched zip operation with βcreate pair/tupleβ operation in my head. Thanks for clarification.