adventofcode 2023-12-10

Day 10 - Solutions

@michaeljweaver thanks a lot for pointing to https://en.wikipedia.org/wiki/Point_in_polygon and the trick, it helped me solve the part 2 ๐Ÿ™Œ๐Ÿป. Iโ€™m not good at geometry โ˜บ๏ธ

Also used the even-odd rule for part 2. Part 1 was fun, if kind of long to code. I'll be revising this code later; I have some hard-coded values I don't like to see. https://github.com/rjray/advent-2023-clojure/blob/master/src/advent_of_code/day10.clj

๐Ÿ‘ 1

Nice task! For part 2 after unsuccessful tries with ray-crossing etc finally I just zoomed input field in 2 times, fill the area and check allinitial tiles in filled set. A bit surprized that we have to calculate all internal tiles (not only ground), so I had to make my zoom pipes different than initial ones.

Here is how the pipe looks like.

๐Ÿ”ฅ 4
โ˜๏ธ 1

I'm so close, but my flood fill is filling everything ๐Ÿ˜•

And mine zoomed x2

I got it! spent more than one hour looking for a hole in my flood fill. off by one error; turns out I was skipping the position adjacent to the starting one. for part 2 I decided to zoom in like @andrey.yallowsack.com

(def expand
  {\| [".X."
       ".X."
       ".X."]
   \- ["..."
       "XXX"
       "..."]
   \L [".X."
       ".XX"
       "..."]
   \7 ["..."
       "XX."
       ".X."]
   \J [".X."
       "XX."
       "..."]
   \F ["..."
       ".XX"
       ".X."]
   \. ["..."
       "..."
       "..."]})
debugging this one was a chore, but very satisfying to get it right at the end https://github.com/FelipeCortez/advent-of-code/blob/master/2023/10.clj

I have my stars for Day 10, but boy it was a slog. Iโ€™ve got to clean up my code a bit before I post. Probably in the morning (my morning).

๐Ÿคช 1

https://gitlab.com/maximoburrito/advent2023/-/blob/main/src/day10/main.clj I couldn't figure out how to make what I thought was the obvious solution work, so instead I literally converted the pipe map to 3x size so I could do a trivial bfs to find what is inside and outside. Looking at @michaeljweaver's solution, I'm still not entirely sure why it works and why you don't have to also check vertically, but I'm sure it'll make more sense in the morning ๐Ÿ™‚

https://github.com/erdos/advent-of-code/blob/master/2023/day10.clj For the second part, I went through the path again and cleared all other cells. Then I went thought the path the third time and kept track of the cells to my left hand side and used these as an input to a flood fill.

I did an https://en.wikipedia.org/wiki/Point_in_polygon algorithm for determining whether a point is inside a polygon. I tried to be fancy and check along rows or columns depending on which edge was closer, but I gave that up and just checked โ€˜aboveโ€™.

๐Ÿ‘ 1

looks like we have 3 merely different approaches so far.

The trick was that if these types of patterns are above a point:

7   F
|   |
J   L
they donโ€™t count as crossing, but these do count:
7   F
|   |
L   J
and obviously
-
counts as a crossing.

๐Ÿ‘ 1
๐Ÿ˜ 3

Omg day 10 took far too long, I think itโ€™s time for me to bow out of advent of code so I have some headspace for my real job https://github.com/danielneal/advent-of-code-2023/blob/main/src/day10.clj

This one took me much too long and the code didnโ€™t end up nice either ๐Ÿ˜• at least its solvedโ€ฆ Also went with the even-odd rule