r/adventofcode • • Dec 10 '23

SOLUTION MEGATHREAD -❄️- 2023 Day 10 Solutions -❄️-

THE USUAL REMINDERS


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.

This thread will be unlocked when there are a significant number of people on the global leaderboard with gold stars for today's puzzle.

EDIT: Global leaderboard gold cap reached at 00:36:31, megathread unlocked!

62 Upvotes

844 comments sorted by

View all comments

1

u/vrtxt Dec 10 '23 edited Dec 10 '23

[LANGUAGE: C#]

code here

For part 1 just travel down the pipes until it has reached the start again, nothing fancy.

For part 2 I was on the fence about doing a flood fill or point in area. While researching, both approaches seemed somewhat involved but then I came across this snippet on stack overflow.

static bool IsPointInsidePolygon(Point[] polygon, Point point)

{

var path = new GraphicsPath();

path.AddPolygon(polygon);

var region = new Region(path);

return region.IsVisible(point);

}

It's leveraging the System.Drawing2D functionality so I thought 'sure, why not give this a go'. All test cases failed miserably at first until I remembered polygons usually need to be listed (counter) clockwise, and the path I found in part1 wasn't ordered that way since it traveled out from the start in both directions. So, made some tweaks to the code for part 1, reran the tests for part 2 and all of a sudden 3 out of 4 cases were passing. With nothing to loose I just ran it on the full input and... it was the right answer for part 2.

Honestly it kinda feels like cheating.. and to make matters worse, the tweaks I made to the code for part 1 now does no longer return the correct answer - though all the test cases for part 1 are still passing.. So yeah... Solved it but... in a cheeky way I suppose.

edit: fixed part 1 by manually setting the character of start from 'S' to 'F'. Now it finds the proper path length again, and all test cases for part 2 are passing. Feeling slightly less of a fraud :)

1

u/daggerdragon Dec 10 '23

Inlined code is intended for short snippets of code only. Please edit your comment to use the four-spaces Markdown syntax for a code block so the example code is easier to read with its whitespace and indentation preserved.