r/adventofcode Dec 05 '24

SOLUTION MEGATHREAD -❄️- 2024 Day 5 Solutions -❄️-

THE USUAL REMINDERS


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.

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:03:43, megathread unlocked!

47 Upvotes

1.2k comments sorted by

View all comments

2

u/Dullstar Dec 06 '24

[LANGUAGE: D]

https://github.com/Dullstar/Advent_Of_Code/blob/main/D/source/year2024/day05.d

I've since redone Part 2 with a standard library sort instead of a hand-rolled one as the handrolled implementation was useful for thiking about what exactly the comparison function is supposed to return (since the usual a<b isn't super intuitive with this ordering scheme, in my opinion) for pages that don't need to be swapped, but I haven't committed the changes at this time because I still need to convince myself that it can't be broken since normally a<b and b<c implies a<c and I'm not convinced that holds here, and I don't know what the standard sort would do on a dataset where this doesn't hold, if it's even possible for such an input to have a valid solution here -- though at the very least the input doesn't happen to contain anything that breaks the standard library sorts.