This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
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).
My (not very elegant) https://github.com/wevre/advent-of-code/blob/master/src/advent_of_code/2023/day_10_pipes.clj.
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 @UTFAPNRPT'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’.
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.@UTFAPNRPT thanks a lot for pointing to https://en.wikipedia.org/wiki/Point_in_polygon and the trick, it helped me solve the part 2 🙌:skin-tone-2:. I’m not good at geometry ☺️
cleaned the code up, wrote a fn to determine start shape https://github.com/zelark/AoC/blob/master/src/zelark/aoc_2023/day_10.clj
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
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.
All credits go to @UTFAPNRPT, but here I am : https://github.com/arnaudgeiser/advent-of-code/blob/master/2023/clojure/src/advent_of_code/day10.clj
And my verbose solution... https://github.com/genmeblog/advent-of-code/blob/master/src/advent_of_code_2023/day10.clj
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 @U05T4JC21J6
(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.cljHi folks! My Day 10 https://github.com/mtravers/aoc2023/blob/main/src/aoc2023/day10.clj
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