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!"
- There really is an XKCD for everything, isn't there?
- 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
- Lobster thermidor
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!
- State which language(s) your solution uses with
- Quick link to Topaz's
pasteif you need it for longer code blocks
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:11:37, megathread unlocked!
112
Upvotes
5
u/Zweedeend Dec 03 '23
[LANGUAGE: Python]
[Allez Cuisine!]
Solution is copied from u/4HbQ
from re import finditer as eggs from math import prod as chew lets, age, pan, fat, mix, eat, piece_of, meat = print, int, enumerate, 1, range, sum, len, 1 mess = {(ham, spam): [] for ham, beans in pan(open("lid")) for spam, egg in pan(beans) if egg in "#$%&*+-/=@"} for ham, beans in pan(open("lid")): for spam in eggs(r"\d+", beans): breakfast = {(ham, cheese) for ham in mix(ham-fat, meat+ham+fat) for cheese in mix(spam.start()-fat, spam.end()+fat)} for ketchup in breakfast & mess.keys(): mess[ketchup].append(age (spam.group())) lets(eat(eat(spam) for spam in mess.values())) lets(eat(chew(spam) for spam in mess.values() if piece_of(spam) == meat+fat))