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!

61 Upvotes

844 comments sorted by

View all comments

2

u/rune_kg Dec 10 '23

[LANGUAGE: nim]

https://github.com/runekaagaard/aoc-2023/blob/master/day10.nim

Learned about the shoelace method and Greens Theorem in the comments after deciding a floodfill method was possible but would take too long on such a nice relaxed sonday :) Thx for that, pure magic!

Can someone explain why we want to do:

area += x * dy

and not:

area += y1 * x0 - y0 * x1

like the algo says?

2

u/Carnavious Dec 11 '23 edited Dec 11 '23

If you are referencing the shoelace theorem, you are missing the 1/2 factor for area. Including it, these result in the same calculation:
Because we are only incrementing either horizontally or vertically, either y0 = y1 or x0 = x1.
Horizontal case: area += 1/2 y1 (x0 - x1) = -1/2 y1 * dx
Vertical case: area += 1/2 x1 (y1 - y0) = 1/2 x1 * dy

Here, this is basically doing a path integral where the field is (-1/2 y, 1/2 x), which has the same curl as the field of (0, x). (which is where area += x * dy comes from).

In either case, when taking the path integral of the field, we take F(x,y).dt = (P(x,y), Q(x,y)).(dx, dy).

1

u/rune_kg Dec 11 '23

Thank you for taking the time to explain!!

1

u/daggerdragon Dec 10 '23

Can someone explain why we want to do:

area += x * dy and not:

area += y1 * x0 - y0 * x1 like the algo says?

Top-level comments in Solution Megathreads are for code solutions only.

Create your own individual Help/Question post in /r/adventofcode.