Advent of Code 2023 (Day13)
I still had to take my time to comprehend the problem description each time - but I managed to pass it.
Day13-
From top of the grid, compare each row. If
row[i] == row[i+1]
, then the two might be the pair we are looking for. -
Calculate the boundary. To do that, compare
i (the num of rows you have upward)
andgrid.length - i - 2 (the num of rows you have downward)
and pick up the smaller one. -
Set j = 1 and compare
row[i-j]
androw[i+1+j]
. If the two are not the same, thei
is not the horizontal line you want -> back to#1
. If the two are the same, then incrementj
and compare them until they reaches the boundary. -
If the two reaches the boundary, it means you found the horizontal line index.
-
Just do the same way to columns in the grid.
Here is my code.
Thanks for reading ✌️