r/adventofcode • • Dec 08 '23

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

THE USUAL REMINDERS


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
  • Visualizations using 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.

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

968 comments sorted by

View all comments

1

u/[deleted] Dec 08 '23 edited Dec 08 '23

[LANGUAGE: Python]

The second part was hard using dictionaries and for loops until I realized that it was about Least Common Multiple or LCM. The only thing you have to do is to get the target node for all nodes that ends with "A". Then just get the steps for those pairs of nodes. Finally, just get the LCM of those values and done.

This works because the puzzle input is like an automaton. So, you have to advance N steps to reach the node with the maximum steps at the first iteration.

Sample Image

Here you have the code: https://github.com/crixodia/aoc/tree/main/2023/08_haunted_wasteland

1

u/daggerdragon Dec 08 '23

FYI: do not share your puzzle input which also means do not commit puzzle inputs to your repo without a .gitignore.

Please remove (or .gitignore) the input files from your repo and scrub them from your commit history.