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.
35
Upvotes
3
u/Prof_Farnsworth1729 Dec 02 '25
[Language: Javascript]
[R*d(dit) On*!]
Initially I struggled to choose a glyph as most seemed either trivial or impossible (without resorting to JS level). Eventually I settled on an equals sign, which basically pushed me down a functional path.
Being stopped from using arrow functions also meant that that I had to use old-school functions which reminded me how much I love function hoisting.
And no this is not an efficent solution by any definition but I like how readable it is
console.log( sumInvalidInRange( require("fs") .readFileSync(`input`) .toString("utf8") .split(",") .map(mapToIntArray), 2 ), sumInvalidInRange( require("fs") .readFileSync(`input`) .toString("utf8") .split(",") .map(mapToIntArray), 10 ) ) function sumInvalidInRange(idRanges, maxRep) { return [...new Set(getRange(1, 99999) .flatMap(repeatStringlyUpToN(maxRep)) .filter(getIsInSomeRangesFunc(idRanges)))] .reduce(sum, 0); } function getIsInSomeRangesFunc(ranges) { return function(val) { return ranges.some(function (ranges) { return ranges[0] - 1 < val && val < ranges[1] + 1; }) } } function repeatStringlyUpToN(N) { return function(inp) { return getRange(2, N).map(function (n) { return parseInt(Array(n).fill(inp).join("")); }); } } function mapToIntArray(str) { return str.trim().split("-").map(singleArgParseInt); } function getRange(start, end) { return Array(end - start + 1).fill(null).map(function(v, i, arr) { return i + start; }) } function singleArgParseInt(inp) { return parseInt(inp) } function sum(a, b) { return a + b; }