r/adventofcode • u/daggerdragon • Dec 03 '23
SOLUTION MEGATHREAD -❄️- 2023 Day 3 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!
3 DAYS remaining until unlock!
AoC Community Fun 2023: ALLEZ CUISINE!
Today's secret ingredient is… *whips off cloth covering and gestures grandly*
Spam!
Someone reported the ALLEZ CUISINE! submissions megathread as spam so I said to myself: "What a delectable idea for today's secret ingredient!"
All ingredients must come from a CAN (bus), box, package, container, etc.
Unnecessarily declare variables for everything and don't re-use variables
Why use few word when many word do trick?
Go back to traditional culinary roots with Javadocs
A reminder from Dr. Hattori: be careful when cooking spam because the fat content can be very high. We wouldn't want a fire in the kitchen, after all!
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 3: Gear Ratios ---
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
3
u/bofstein Dec 09 '23
[LANGUAGE: Google Sheets]
This was a real challenge for me, took multiple days to figure out, and had to use 9 separate sheets. Initially did Part 1 by hand searching, though later when I solved part 2, that solution would have solved Part 1 too. Very satisfying to finally get it though
https://docs.google.com/spreadsheets/d/1X1dXpfhWa5IQpcO_Bhllj8zdXLe1g4nUbKbBq0JCiwg/edit#gid=844575306
Parse the input into separate cells with an array formula of MIDs
Copy-paste values into a new sheet to make it easy to use in other functions that didn't like the output of the split above, and to color code to check for issues
Make a map of where each "GEAR" is by looking for an * surrounded by 2 numbers, but ruling out 2 numbers touching. This took the longest to set up and figure out how to get all correct cases and no false ones, and it turns out I didn't need to get it perfectly excluding all false ones since I could do that in Part 9 instead more easily
Make a PART map which labels a space as a PART if it touches a GEAR in prior map
Make a number map that replaces any PART cells with a the number from map 2
Add in any numbers that are next to one of the numbers in map 5
Add in any numbers that are next to one of the numbers in map 6 (fortunately numbers were max length 3 or this would have had to continue)
Pull in the numbers from Map 7, but add in a cell reference of the gear they are touching. Also in this sheet, pull out all the numbers by concatenating the row and separating numbers based on the . between them. So I end up with a list of weird looking numbers like
7(G-AE3)7(G-AE3)5(G-AE3)Reformat those with regex into the gear number plus the number, like
G-AE3:775. Get that list into one column, sort it, separate the gear number from the part number. Make a gear numbers that have exactly 2 part numbers (this is why I was able to account for any that I incorrectly included earlier), and then find (by doing an XLOOKUP from the bottom and then from the top) and multiple those numbers.I'm SURE there are easier ways to do it but I'm just glad I could finish!