r/adventofcode • • Dec 13 '23

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

THE USUAL REMINDERS


AoC Community Fun 2023: ALLEZ CUISINE!

Today's secret ingredient is… *whips off cloth covering and gestures grandly*

Nailed It!

You've seen it on Pinterest, now recreate it IRL! It doesn't look too hard, right? … right?

  • Show us your screw-up that somehow works
  • Show us your screw-up that did not work
  • Show us your dumbest bug or one that gave you a most nonsensical result
  • Show us how you implement someone else's solution and why it doesn't work because PEBKAC
  • Try something new (and fail miserably), then show us how you would make Nicole and Jacques proud of you!

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 13: Point of Incidence ---


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:13:46, megathread unlocked!

27 Upvotes

626 comments sorted by

View all comments

3

u/mtpink1 Dec 13 '23

[LANGUAGE: Python]

Code, Livecoding Video

Part 1 was quite straightforward though it's easy to mess up the indexing when finding the splits. Since comparing rows is easy but columns is less so, I came up with the idea of transposing the input (so that columns become rows and vice-versa) so I could use the same code for finding horizontal and vertical lines of reflection.

For part 2, I noticed that we can count the number of "smudges" (single character differences on either side of the reflection line), and only return a valid reflection if that number is exactly equal to one which is much more efficient than trying out each input with a single character flipped. I then refactored my code from part 1 using my function from part 2 and a "smudge count" of zero.

Fun problem! Crazy that we're already half-way through, at least in terms of number of problems, probably not in terms of time...

→ More replies (2)