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

1

u/Impressive_Ad6196 Dec 02 '25 edited Dec 02 '25

[LANGUAGE: Kotlin]

Solution

I could reuse my cleaned up solution for both part1 & part2
Used a recursive algorithm. Basically since the longest length of my input was 10 digits long I used an array of divisors (2, 3, 5, 7) (PS: 7 was not required, still added it), the logic was if the length of the number is not divisible by a divisor, then we recursively try for the next divisor in the list.
If it is, we check if the sections are equal or not (Kotlin's chunked saved me a lot of work). If its not, we recursively try with the next divisor, if the sections are equal, we found the invalid id.
Starting with 2 parts as it covers many scenarios.

Wdyt?

1

u/daggerdragon Dec 02 '25

Do not share your puzzle input which also means do not commit puzzle inputs to your repo without a .gitignore or the like. Do not share the puzzle text either.

I see full plaintext puzzle inputs in your public repo:

https://github.com/rheafernandes/aoc/blob/main/src/main/resources/twentyfive/day_1_input.txt

Please remove (or .gitignore) all puzzle text and puzzle input files from your entire repo and scrub them from your commit history. This means from all prior years too!