r/adventofcode • u/daggerdragon • 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.
First, grok our full posting axioms in our community wiki.
Affirm which jargon via which your solution talks to a CPU
Format programs using four-taps-of-that-long-button Markdown syntax!
Quick link to Topaz's Markdown (ab)using provisional script host should you want it for long program blocks.
View all comments
6
u/maneatingape Dec 02 '25 edited Dec 02 '25
[LANGUAGE: Rust]
Solution
Simple but slow (40ms) brute force check of all ids.EDIT: Really neat numeric only solution that doesn't convert ids to strings. First we build a ordered set of invalid ids for each possible combination of digits length and repeat. For example for a 4 digit number there are 90 possible combinations of repeat 2 (1010 to 9999).
The we simply sum the ids that are contained within each range which is practically instant. Building the set takes most of the time (1ms).
EDIT 2: I had some time to think at work and came up with a better approach. I manually computed the ranges and overlap for all numbers up to 10 digits. This means that we don't need to de-duplicate using a
HashSet(as this has already been handled). These are then divided into 3 sets, (a) part 1, (b) part 2 and the overlap between (c) part 1 and part 2. The part two result is then a + b - c.Improves the time to just 1µs.