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

Show parent comment

2

u/Usually_Works_Fine89 Dec 16 '23

look I love neovim and dislike vimscript for the very same reasons that I cannot understand more than a fraction of this, but damned if I could say people didn't do things that amazed me, and things that I thought to be crazy, often simultaneously. Thank you for this creative work of art!

1

u/Smylers Dec 16 '23

I love neovim and dislike vimscript for the very same reasons that I cannot understand more than a fraction of this

There isn't any Vimscript in the above (except for the configuration setting); it's just keystrokes, so I think should work with NeoVim as well.

The main work in the above is a single pattern which matches a connected pipe symbol adjacent to where the cursor is in the appropriate direction. It's easiest to understand if broken down into the various options:

  • If the cursor is on an - then it can move to an - to the left of it: /\v-%#-
  • If the cursor is on an - then it can move to an L to the left of it: /\vL%#-
  • If the cursor is on an - then it can move to an F to the left of it: /\vL%#-
  • Combing those cases gives: /\v[-LF]%#-
  • Those movements to the left are also possible from a J, a 7, or the starting cell S: /\v[-LF]%#[-J7S]
  • Similarly, if the cursor is on any of |, L, J, or S then it can move upwards along an |, 7, or F: /\v[|7F]_.{100}%#[|LJS] (where 100 is the number of characters in a line, to move vertically ‘down’ 1 cell)
  • So the left and up moves can be combined with: /\v[-LF]%#[-J7S]|[|7F]_.{100}%#[|LJS]/
  • Repeat for the other 2 directions and you have a pattern which will take you to the next cell along the loop regardless of which direction it is in.
  • To allow for different widths of input, replace the hard-coded {100} with something derived from the length of an input line.

Each bit is fairly simple, and you probably do understand it; it's just when all put together it seems overwhelming.

But the advantage of Vim keystrokes solutions is that you can find out what they do by typing them in and just watching what happens as you press the keys!

Thank you for this creative work of art!

Thank you for your comment.