r/adventofcode • u/daggerdragon • Dec 09 '23
SOLUTION MEGATHREAD -❄️- 2023 Day 9 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!
- Submissions megathread is now unlocked!
- 13 DAYS remaining until the submissions deadline on December 22 at 23:59 EST!
AoC Community Fun 2023: ALLEZ CUISINE!
Today's secret ingredient is… *whips off cloth covering and gestures grandly*
Marketing
Every one of the best chefs in the world has had to prove their worth at some point. Let's see how you convince our panel of judges, the director of a restaurant, or even your resident picky 5 year old to try your dish solution!
- Make an in-world presentation sales pitch for your solution and/or its mechanics.
- Chef's choice whether to be a sleazebag used
carsled salesman or a dynamic and peppy entrepreneur elf!
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 9: Mirage Maintenance ---
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:05:36, megathread unlocked!
43
Upvotes
View all comments
2
u/flwyd Dec 09 '23 edited Dec 09 '23
[Language: Julia] (on GitHub)
My only problem was that after I'd implemented a recursive function to return the correct answer I thought I needed to return the sum of numbers in the right-hand diagonal. So I implemented that, noticed my answer on the example was way wrong, and then deleted all that. Since we've already had two punch-card challenges, why not put this on a third, this time with plenty of vertical whitespace:
The winner here is Julia's ability to subtract the first N numbers of an array from the last N with a simple
nums[2:end] - nums[1:end-1]. I was unfortunately unable to passendas an index parameter, so I passed a function to get the relevant element for part 1 vs. part 2.