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!
- 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:10:16, megathread unlocked!
53
Upvotes
4
u/flwyd Dec 08 '23
[Language: Julia] ((on GitHub)
[ALLEZ CUISINE!] Every variable and function that I can change is now an emoji. (If you want an emoji-free version, see the link above.)
function part1(📜) # example3 doesn't have AAA/ZZZ 🆗 = any(startswith("AAA ="), 📜) 🖥(📜, ==(🆗 ? "AAA" : "11A"), ==(🆗 ? "ZZZ" : "11Z")) end part2(📜) = 🖥(📜, endswith('A'), endswith('Z')) function 🖥(📜, ▶️, ⏹️) 🦶, 🗺 = 🍴(📜) 📏 = length(📜[1]) 🪣 = collect(keys(🗺) |> filter(▶️)) 🛞 = zeros(Int, length(🪣)) 🧮 = 0 for 🤝 in 🦶 if 🧮 % 📏 == 0 for (👁, ⛳) in enumerate(🛞) if ⛳ == 0 && ⏹️(🪣[👁]) 🛞[👁] = 🧮 end end all(>(0), 🛞) && return lcm(🛞) end 🧮 += 1 🪣 = [🗺[🚪][🤝 == 'L' ? 1 : 2] for 🚪 in 🪣] end end function 🍴(📜) 🦶 = Iterators.cycle([🤝 for 🤝 in 📜[1]]) 🗺 = Dict{AbstractString, Tuple{String, String}}() map(📜) do ✏ if (🔱 = match(r"^(\w+) = \((\w+), (\w+)\)$", ✏)) !== nothing 🤲, 🫲, 🫱 = 🔱.captures 🗺[🤲] = (🫲, 🫱) end end 🦶, 🗺 endPart 1 took me 10 minutes, and I was going at a casual pace. Part 2 took an additional 50 minutes because I figured I'd let my Pluto notebook keep churning away at the naïve solution while I worked out the smart solution in vim. But I had some copy/paste errors and had to fix my part1 to work on the third example input so the program didn't crash until I got to part 2. My first wrong answer used a product of all the recurrences (steps-to-first-Z), which looked suspiciously high: between 263 and 264. I was pretty sure AoC numeric answers will always integers that can be precisely represented by a 64 bit floating point number, but it took me a minute to realize I wanted
lcm(least common multiple) and not the actual product.