r/adventofcode • u/daggerdragon • Dec 08 '23
SOLUTION MEGATHREAD -❄️- 2023 Day 8 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!
- 14 DAYS remaining until the submissions deadline on December 22 at 23:59 EST!
AoC Community Fun 2023: ALLEZ CUISINE!
Today's theme ingredient is… *whips off cloth covering and gestures grandly*
International Ingredients
A little je ne sais quoi keeps the mystery alive. Try something new and delight us with it!
Code in a foreign language
- Written or programming, up to you!
- If you don’t know any, Swedish Chef or even pig latin will do
- Test your language’s support for Unicode and/or emojis
Visualizationsusing Unicode and/or emojis are always lovely to see
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 8: Haunted Wasteland ---
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
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:10:16, megathread unlocked!
52
Upvotes
View all comments
Show parent comment
3
u/mgtezak Dec 16 '23
You’re exactly right! When i first read the problem description i thought to myself: Wow, this is an incredibly hard problem, especially for day 8! First of all it was obvious that the individual paths would start to cycle at some point, but do we really have to find the beginning of each cycle and then figure out the length of each cycle and then figure how many Z-nodes there were in each cycle and then figure out some mathematical formula to calculate how these Z-occurrences align across cycles?!Then I thought: AoC probably included some hidden regularities in the puzzle input, which will make finding to solution way easier, so i made two assumptions (which turned out to be correct):
From these two assumptions it follows that each cycle has the exact same length as the initial A-Z path and only contains a single Z node and that this Z node will be the very last one in each cycle (a better way to think about it is that it's the first one in each cycle because it replaces the initial A-node: It's the current node as one reads the first of the directions). In this case using the least common multiple (lcm) is the correct answer.
But you’re completely right that these assumptions are not confirmed anywhere in the problem statement, which is a bit misleading and will make the problem look way harder than it actually is.