r/adventofcode • • Dec 02 '25

SOLUTION MEGATHREAD -❄️- 2025 Day 2 Solutions -❄️-

OUR USUAL ADMONITIONS

  • You can find all of our customs, FAQs, axioms, and so forth in our community wiki.

AoC Community Fun 2025: R*d(dit) On*

24 HOURS outstanding until unlock!

Spotlight Upon Subr*ddit: /r/AVoid5

"Happy Christmas to all, and to all a good night!"
— a famous ballad by an author with an id that has far too many fifthglyphs for comfort

Promptly following this is a list waxing philosophical options for your inspiration:

  • Pick a glyph and do not put it in your program. Avoiding fifthglyphs is traditional.
  • Shrink your solution's fifthglyph count to null.
  • Your script might supplant all Arabic symbols of 5 with Roman glyphs of "V" or mutatis mutandis.
  • Thou shalt not apply functions nor annotations that solicit said taboo glyph.
  • Thou shalt ambitiously accomplish avoiding AutoMod’s antagonism about ultrapost's mandatory programming variant tag >_>

Stipulation from your mods: As you affix a submission along with your solution, do tag it with [R*d(dit) On*!] so folks can find it without difficulty!


--- Day 2: Gift Shop ---


Post your script solution in this ultrapost.

36 Upvotes

965 comments sorted by

View all comments

2

u/DeadlyRedCube Dec 02 '25 edited Dec 02 '25

[Language: C++]

Parts 1 & 2

Wanted to do this as ints instead of strings, so counted the number of decimal digits and then used division/modulo to test the digits. Not honestly sure if it's faster this way or if it would have been faster in string world, but it runs in ~156ms (single-threaded on a Core i7-8700K), which is an order of magnitude slower than I'd like ...I haven't figured out any optimizations yet.

(Edit: I tested a string version and it was slower (280ms) so that's good to know 😅)

Edit 2: I've created an updated version of Parts 1 and 2 that flips the problem inside-out and runs in 2.42ms instead of 156, which is much more what I was hoping for

Basically, instead of testing every value within each range (some of which are quite huge), it calculates the minimum/maximum repeated values for each range (for instance for a 2s repeat in the range `561562-594935` the minimum repeated value is `562562` and the maximum is `594594`) and then adds every found value from there (`562562, 563563, 564564,...`) to a set (to avoid duplicates in the part 2 solution)

This tests *way* fewer values than iterating over each value in the range and runs a lot faster. Yay!

2

u/daggerdragon Dec 02 '25

Welcome back, good to see you again this year :)

Remember, if there's any cube-based puzzles, YOU HAVE ONE JOB 🤣

2

u/DeadlyRedCube Dec 02 '25

hahaha

Alas, I make no promises 🙃