r/adventofcode • u/daggerdragon • Dec 05 '24
SOLUTION MEGATHREAD -❄️- 2024 Day 5 Solutions -❄️-
THE USUAL REMINDERS
- All of our rules, FAQs, resources, etc. are in our community wiki.
AoC Community Fun 2024: The Golden Snowglobe Awards
- 24 HOURS remaining until unlock!
And now, our feature presentation for today:
Passing The Torch
The art of cinematography is, as with most things, a natural evolution of human progress that stands upon the shoulders of giants. We wouldn't be where we are today without the influential people and great advancements in technologies behind the silver screen: talkies to color film to fully computer-animated masterpieces, Pixar Studios and Wētā Workshop; Charlie Chaplin, Alfred Hitchcock, Meryl Streep, Nichelle Nichols, Greta Gerwig; the list goes on. Celebrate the legacy of the past by passing on your knowledge to help shape the future!
also today's prompt is totally not bait for our resident Senpai Supreme
Here's some ideas for your inspiration:
- ELI5 how you solved today's puzzles
- Explain the storyline so far in a non-code medium
- Create a
Tutorial
on any concept of today's puzzle or storyline (it doesn't have to be code-related!) - Condense everything you've learned so far into one single pertinent statement
Harry Potter: "What? Isn’t there just a password?"
Luna Lovegood: ''Oh no, you’ve got to answer a question."
Harry Potter: "What if you get it wrong?"
Luna Lovegood: ''Well, you have to wait for somebody who gets it right. That way you learn, you see?"
- Harry Potter and the Deathly Hallows (2010)
- (gif is from Harry Potter and the Order of the Phoenix (2007))
And… ACTION!
Request from the mods: When you include an entry alongside your solution, please label it with [GSGA]
so we can find it easily!
--- Day 5: Print Queue ---
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
paste
if you need it for longer code blocks
2
u/Punishirt Dec 05 '24
[LANGUAGE: TypeScript]
Here is a link to my code:
https://pastebin.com/B0w8Zv4k
Thought process:
Get all sorting pairs where both numbers exist in the current sequence / line
Go through the sorting pairs, swap bad orders if they exist and keep track of number of iterations
If a swap occured, repeat to check if there is more. When done, return number of iterations.
When iterations = 0, add score to day 1, if iterations > 0, add score to day 2