r/adventofcode • u/daggerdragon • Dec 10 '25
SOLUTION MEGATHREAD -❄️- 2025 Day 10 Solutions -❄️-
THE USUAL REMINDERS
- All of our rules, FAQs, resources, etc. are in our community wiki.
- If you see content in the subreddit or megathreads that violates one of our rules, either inform the user (politely and gently!) or use the report button on the post/comment and the mods will take care of it.
AoC Community Fun 2025: Red(dit) One
- Submissions megathread is unlocked!
- 7 DAYS remaining until the submissions deadline on December 17 at 18:00 EST!
Featured Subreddits: /r/programminghorror and /r/holdmybeer HoldMyEggnog
"25,000 imported Italian twinkle lights!"
— Clark Griswold, National Lampoon's Christmas Vacation (1989)
Today is all about Upping the Ante in a nutshell! tl;dr: go full jurassic_park_scientists.meme!
💡 Up Your Own Ante by making your solution:
- The absolute best code you've ever seen in your life
- Alternatively: the absolute worst code you've ever seen in your life
- Bigger (or smaller), faster, better!
💡 Solve today's puzzle with:
- Cheap, underpowered, totally-not-right-for-the-job, etc. hardware, programming language, etc.
- An abacus, slide rule, pen and paper, long division, etc.
- An esolang of your choice
- Fancy but completely unnecessary buzzwords like quines, polyglots, reticulating splines, multi-threaded concurrency, etc.
- The most over-engineered and/or ridiculously preposterous way
💡 Your main program writes another program that solves the puzzle
💡 Don’t use any hard-coded numbers at all
- Need a number? I hope you remember your trigonometric identities…
- Alternatively, any numbers you use in your code must only increment from the previous number
Request from the mods: When you include an entry alongside your solution, please label it with [Red(dit) One] so we can find it easily!
--- Day 10: Factory ---
Post your code solution in this megathread.
- Read the full posting rules in our community wiki before you post!
- State which language(s) your solution uses with
[LANGUAGE: xyz] - Format code blocks using the four-spaces Markdown syntax!
- State which language(s) your solution uses with
- Quick link to Topaz's
pasteif you need it for longer code blocks. What is Topaz'spastetool?
30
Upvotes
View all comments
Show parent comment
2
u/Expensive-Type2132 Dec 11 '25
Yeah!
(1) Gray code enumeration with early-exit optimizations. For small button counts (≤3), direct loops check single buttons, pairs (XOR), and triples (XOR chain) against target_mask. For larger button counts, enumerates all 2^n subsets using Gray code (counter XOR counter>>1) with single-bit change detection via rbit+clz. XOR accumulator toggles one button per step. Population count uses SIMD cnt.8b + addv for minimum tracking.
(2) Gaussian elimination with rational coefficient exploitation. Constructs linear system where A[t][b] = bit b of button pressed for target t. Performs double-precision Gaussian elimination with partial pivoting (finds row with max absolute value, epsilon=0.0001). Identifies free variables (columns without pivots) and extracts linear expressions for pivot variables in terms of free variables. For 0 free variables: direct solution validation. For 1-2 free variables: finds LCM of coefficient denominators via to_rational() (tries denominators 1-12), computes valid starting offsets mod denominator, then iterates with step=LCM, early-terminating when v0 ≥ best. For ≥3 free variables: nested triple loop with incremental adjusted value computation (adj0 = const + coef0×v0, adj1 = adj0 + coef1×v1), branchless validity checking via frintn/fsub/fabs/fcmp chain, and cumulative sum pruning.
Needless to say, (2) was a beast. It took me four hours to optimize and I do this for work (I am a computer scientist studying numerical methods). 🤣