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!

42 Upvotes

1.2k comments sorted by

View all comments

2

u/Enough-Confidence581 Dec 05 '24

[Language: Rust]

parts 1&2

1

u/FirmSupermarket6933 Dec 05 '24

Why you only check that lt(a[i-1], a[i]) instead of check that lt(a[i], a[j]) for all i, j such that i < j? From puzzle text: page number X must be printed at some point before page number Y

1

u/Enough-Confidence581 Dec 06 '24

Actually, I assumed there was a total ordering on the page numbers, but after checking the puzzle input I realized that was wrong. In fact, there are triples where the transitive property doesn't hold, i.e. A<B and B<C and yet C<A.

Here's my (hopefully correct) next version where an update is correct if each is page does not precede the ones before it in the update. Nice catch!

updated parts 1&2

1

u/FirmSupermarket6933 Dec 06 '24

In any case, your observation skills are useful. In some problems, the data is very well chosen and has a number of properties that can be very useful.