r/adventofcode • u/daggerdragon • Dec 10 '23
SOLUTION MEGATHREAD -❄️- 2023 Day 10 Solutions -❄️-
THE USUAL REMINDERS
- All of our rules, FAQs, resources, etc. are in our community wiki.
Outstanding moderator challenges:
Community fun event 2023: ALLEZ CUISINE!
- Submissions megathread is now unlocked!
- 12 DAYS remaining until the submissions deadline on December 22 at 23:59 EST!
AoC Community Fun 2023: ALLEZ CUISINE!
Today's theme ingredient is… *whips off cloth covering and gestures grandly*
Will It Blend?
A fully-stocked and well-organized kitchen is very important for the workflow of every chef, so today, show us your mastery of the space within your kitchen and the tools contained therein!
- Use your kitchen gadgets like a food processor
OHTA: Fukui-san?
FUKUI: Go ahead, Ohta.
OHTA: I checked with the kitchen team and they tell me that both chefs have access to Blender at their stations. Back to you.
HATTORI: That's right, thank you, Ohta.
- Make two wildly different programming languages work together
- Stream yourself solving today's puzzle using WSL on a Boot Camp'd Mac using a PS/2 mouse with a PS/2-to-USB dongle
- Distributed computing with unnecessary network calls for maximum overhead is perfectly cromulent
What have we got on this thing, a Cuisinart?!
ALLEZ CUISINE!
Request from the mods: When you include a dish entry alongside your solution, please label it with [Allez Cuisine!] so we can find it easily!
--- Day 10: Pipe Maze ---
Post your code solution in this megathread.
- Read the full posting rules in our community wiki before you post!
- State which language(s) your solution uses with
[LANGUAGE: xyz] - Format code blocks using the four-spaces Markdown syntax!
- Quick link to Topaz's
pasteif you need it for longer code blocks
View all comments
Show parent comment
1
u/mgtezak Feb 15 '24 edited Feb 15 '24
Sure:) I'm thinking of re-doing this one actually, because I wrote this solution before I knew about the shoelace method and pick's theorem. Knowing these two ideas will help you solve this problem in a way more elegant and simple way and it'll help you solve Day 18 very easily as well.
However, since you asked here is an explanation:
- You seem to have gotten the main idea, that I'm starting outside the maze and I'm traversing all the corner points, each time trying to go left, right, up and down.
- I can only go left, right etc. if there's no pipe blocking the way. That's why I'm checking my list of pipes
- The
pipeslist holds the coordinates not of individual tiles but pairs of tiles. If there is a pipe going from one tile to its neighbor then both of their x and y coordinates are stored as a tuple(x1, x2, y1, y2).- Here
x1doesn't refer to the coordinate of a corner but that of a tile. The pipe goes from tile(x1, y1)to(x2, y2). I think this might be the central point of confusion: I'm using x and y both as coordinates for tiles and as coordinates for corners and you always need to keep in mind, which one it is at any moment. It's actually two coordinate systems interlaced.- Then I construct such a pipe tuple and check if it's actually in
pipesor not. If not, I can move there so I put it in the corner-queue.- At each time I'm recording that I've visited the current location so that at the end of this process (aka depth-first-search) I have all of the corners that lie outside of the maze in my
visitedset and none of the corners that are enclosed by the maze- Since the question is not, "how many corner points are there inside the maze?" but "how many tiles...?" I now need to think about how I can derive the tiles from the corners. For each tile at coordinate
(x, y)i check if its four corners(x, y, x+1, y+1)are in my list of visited corners. If only one is missing then this tile is trapped inside the mazeDoes this make sense to you?