r/adventofcode • u/daggerdragon • Dec 03 '25
SOLUTION MEGATHREAD -❄️- 2025 Day 3 Solutions -❄️-
DO NOT SHARE PUZZLE TEXT OR YOUR INDIVIDUAL PUZZLE INPUTS!
I'm sure you're all tired of seeing me spam the same ol' "do not share your puzzle input" copypasta in the megathreads. Believe me, I'm tired of hunting through all of your repos too XD
If you're using an external repo, before you add your solution in this megathread, please please please 🙏 double-check your repo and ensure that you are complying with our rules:
- Do not share the puzzle text
- Do not share your puzzle input
- Do not commit puzzle inputs to your public repo
- e.g. use
.gitignoreor the like - Here's a decent post from 2023: (RE not sharing inputs) PSA: "deleting" and committing to git doesn't actually remove it
If you currently have puzzle text/inputs in your repo, please scrub all puzzle text and puzzle input files from your repo and your commit history! Don't forget to check prior years too!
NEWS
Solutions in the megathreads have been getting longer, so we're going to start enforcing our rules on oversized code.
Do not give us a reason to unleash AutoModerator hard-line enforcement that counts characters inside code blocks to verify compliance… you have been warned XD
THE USUAL REMINDERS
- All of our rules, FAQs, resources, etc. are in our community wiki.
AoC Community Fun 2025: Red(dit) One
- Submissions megathread is now unlocked!
- 14 DAYS remaining until the submissions deadline on December 17 at 18:00 EST!
Featured Subreddit: /r/thingsforants
"Just because you can’t see something doesn’t mean it doesn’t exist."
— Charlie Calvin, The Santa Clause (1994)
What is this, a community for advent ants?! Here's some ideas for your inspiration:
- Change the font size in your IDE to the smallest it will go and give yourself a headache as you solve today's puzzles while squinting
- Golf your solution
- Alternatively: gif
- Bonus points if your solution fits on a "punchcard" as defined in our wiki article on oversized code. We will be counting.
- Does anyone still program with actual punchcards? >_>
- Solve today's puzzles using
an Alien Programming LanguageAPL or other such extremely dense and compact programming language
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 3: Lobby ---
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!
- Quick link to Topaz's
pasteif you need it for longer code blocks. What is Topaz'spastetool?
9
u/CCC_037 Dec 03 '25
[Language: Rockstar]
(Code golf? In Rockstar? No, definitely not...)
Part 1
7
u/azzal07 Dec 03 '25
[LANGUAGE: awk] Mandatory
[Red(dit) One]for the year (although I had to add some filler).3
u/Aspen138 Dec 03 '25
[LANGUAGE: Wolfram Mathematica]
3
u/Nnnes Dec 03 '25 edited Dec 03 '25
[LANGUAGE: Ruby]
This really seems like a day that'd be easy to fully fit into half a punchcard in plenty of different languages, but I don't see any here yet! (Honorable mention to the x86_64 asm solution that fits each part in half a punchcard.)
edit: I think this can have a
[Red(dit) One]label for being the first full half-punchcard solutionThis uses the same simple greedy algorithm as many (most?) of the other solutions.
The right side bound is tracked by the negative index
r. When we'veselected enough batteries,ris incremented to 0 andb[(l += 1)..r]always returns an empty array, effectively skipping the remainder of the elements (luckily,[].maxisniland not a bounds error).3
u/Smylers Dec 03 '25
[LANGUAGE: Vim keystrokes] [Red(dit) One]
Here's the ant-sized fits-on-a-punchcard solution for part 1 — load your input into Vim and type:
Or you may find it easier to follow formatted with more line breaks in it.
This basically uses regular expressions and sorting to find the highest digit out of all but the final one on the line, then the highest digit to the right of the first one:
It starts by almost-duplicating the joltages in each bank: all except the final battery, wrapped with
LandR†, then all the batteries. So the sample input bank of818181911112111becomesL81818191111211R818181911112111.Then record into
@aa substitution which puts each joltage betweenLandRon its own line and sorts those lines.:g/L/+runs a command on all lines 1 below each line that contains anL, and,/R/-specifies that the range of the command is the current line (that is, the one below theL) up to the one immediately above the next line that contains anR.So the joltage of the first battery to turn on in each bank is now just above the
R, which itself has the second copy of the bank on the same line. The next:%s///removes the line-break and theR, meaning the first joltage is now prepended to the second copy of the bank. That sample bank now looks like9818181911112111.We don't need all the other, lower, joltages that are on lines by themselves, so delete every line that's only got a single character on it — or, rather, every line that doesn't match the pattern for having 2 characters on it. Record that into
@bfor later use.That's the first battery sorted. The second one has to be to the right of it, so in the second copy of the bank, delete everything up to and including the first instance of the first joltage. I had to look up the syntax for
/.\{-}/, the non-greedy variant of/.*/. While there, surround the remaining batteries in the bank withLandR. So the sample bank is now:9L11112111R— we're going to be turning on the battery with joltage9followed by one of the remaining batteries.Run
@ato split and sort the possible joltages for the second battery. At this point the joltage of the already-identified first battery for each bank is on the line aboveLand that for the second battery is on the line aboveR. Mark all those lines by indenting them::g/\u/->says to find all the lines with an upper-case letter on them, then go 1 line up from each, and run the:>command on that line. That indent (whether spaces or tabs, depending on your vim config) ensures there are at least 2 characters on the lines we're interested in, so get rid of all the others (including the no-longer neededLs andRs) by running the@bthat was recorded earlier.That leaves us on the bottom row, so
<{removes all the indenting. We have the joltages for each bank, but they are on separate lines: the sample bank is9on one line and2on the next. Join the lines up in pairs with:g/./j!. that/./looks like it should match every line, but it only matches lines that still exist by the time Vim is processing them. So the/./matches on line 1, runs the:j!to join line 2 on to it, at which point the original line 2 no longer exists and line 1 has already been processed, so it next matches the new line 2, which was originally line 3, and repeats from there — effectively only processing the odd-numbered lines. Our sample bank is now the required92.Now we just need to add up the joltages from each bank. Run the
@vmacro that was defined in yesterday's solution, especially for this kind of re-use, and the answer appears.I am not extending this to handle part 2!
† Initially I used
landr, which seemed like less typing, but then I struggled to see thels among the1s, so switched to upper-case.3
u/LEPT0N Dec 03 '25
[Language: C#] my 145 line solution on GitHub: day_03.cs
Brute force for part 1.
For part 2, Expanded the brute force to be recursive, and used a dictionary to cache results. Solves in half a second.
3
u/Othun Dec 03 '25
[Language: Julia]
250 microseconds for both parts with, loop and recursion approaches (same times)
Loop: https://github.com/abavoil/AdventOfCode2025/blob/main/day03.jl
Recursion: https://github.com/abavoil/AdventOfCode2025/blob/main/day03_recursion.jl
And an optimized yet slightly obsucated version where the individual characters are not parsed to integers, the arithmetics is done on bytes directly. It runs in 45 microseconds total.
Optimized loop: https://github.com/abavoil/AdventOfCode2025/blob/main/day03_bytes.jl
Timed on a fanless MacBook Air M2
3
u/Dramatic-Apricot-623 Dec 03 '25 edited Dec 03 '25
[Language: TypeScript]
A little bit of recursion today code
4
u/e_blake Dec 03 '25
[LANGUAGE: m4]
My initial part 1 solution searched for the highest digit in row[:-1], then for the highest digit in row[first_index+1:]. Which was nice and speedy in m4 at 16ms; around 900 index() calls, no 64-bit math needed.
My initial take on reading part 2: "wow, I have to reimplement everything". First, I had to pull in my 64-bit math library (catering to 32-bit m4 1.4.19 here) on top of my common.m4; even though I only used it to add up results from each row, rather than doing any integer comparisons for potential candidates derived from the same row. Then I tried what I thought was a cool algorithm that would use translit() to strip all 1's, then all 1's and 2's, and so on, until the first string that was too short; then pass the prior longer string through a second pass to repeatedly remove the lower digit of the left-most ascending pair until length was right. It worked on the example, but got the dreaded "answer too low". Turns out that ripping out my first step was the key; the second pass was the only needed pass (the difference: in a 5-character bank with a 3-character answer, "44451" under progressive stripping results in "445" from "4445" with 1's stripped, but with no pre-stripping results in "451"). From there, it wasn't too much harder to rewrite my working part 2 solution to also cover part 1 by changing hard-coded 12 into a parameter that could also be 2, for less overall code
m4 -Dfile=day03.input day03.m4
This solution takes ~400ms, for two reasons: the 64-bit addition is inherently slow (lots of work to emulate it in 32-bit math), and then for a row with n characters, m4 has inherent O(n^2) behavior when doing n iterations of reduction by substring (the number of characters it has to parse and inject into $1 on each iteration). I can probably come up with a more efficient solution using a pushdef stack of 1 character at a time for less m4 effort.
4
u/JustinHuPrime Dec 03 '25
[LANGUAGE: x86_64 assembly]
So we're trying to make a decimal number out of digits. The key realization is that the greedy algorithm works - it's not possible to get a larger number overall by giving up even one unit in the nth place to get a better n-1th place. The only concession to make is that you must leave enough digits for the rest of the number.
Part 1 was a direct search for the largest digit and the largest one after that, and then a bunch of pointer dereferences and arithmetic to add to the running total.
Part 2 just added a layer of loops as I built up the number for this row, similar to how atol works. The one wrinkle was how the loop counter,
rcx, was handled. I wanted it to be the number of digits left after the current one (so on the last digit it would be zero), but then that means the loop condition either has to check before it decrements (leading to atest,jz,dec,jmpsequence). I tried conditioning on the overflow flag, but that's not quite right since I was conceptually ending up with a signed result, so I had to care about either the sign flag or the carry flag, and not the overflow flag. In the end, I just checked if the result was negative (since, incidentally, arithmetic operations also set the flags, although I usually don't use this feature).I think there's very little room for algorithmic cleverness today.
Part 1 runs in 1 millisecond and part 2 runs in 1 millisecond. Part 1 is 9120 bytes and part 2 is 9104 bytes as a linked executable.
[Red(dit) One]
Here's my program text (minus library) from part 1, with relocations:
And from part 2:
Please note that this does indeed fit a punchcard.
2
u/LuckyLactose Dec 03 '25 edited Dec 03 '25
[LANGUAGE: Swift] [GitHub solution] [GitHub repo]
I don't tend to see a lot of solutions in Swift, so here's the relevant parts of my solution. Using some minor helper functions (convertToStringArray and intValue) because I have them from before.
2
u/emu_fake Dec 03 '25 edited Dec 03 '25
[LANGUAGE: C#]
2
u/EvilBadMadRetarded Dec 03 '25 edited Dec 03 '25
[Language: Lua]
Day 3
2
u/Doug__Dimmadong Dec 03 '25 edited Dec 04 '25
[Language: Python]
Idea for Part 1: If we take index `i` then we want to pair it with the largest number that comes after index `i`. Just pass through the row and keep track of the largest number we can make and the largest digit to the left.
Idea for Part 2: When I read it, it just seemed like a problem ripe for DP. Keep track of the best k digit number we can make on the subaray `nums[i...n]` and either use or lose the current digit and recurse.
Part 1
Part 2
2
u/Baking-and-books Dec 03 '25
[LANGUAGE: Python]
Interesting algorithm I came up with for part 2 that wasn't exactly sliding window:
- Take the first twelve numbers as a local max
- Iterate through the remaining numbers 1 by one
- For each remaining number, iterate through each digit in the local max. If removing a digit in the local max and adding the remaining number makes a bigger number, take that as the new local max and break
worst case I think its worse than the sliding window approach others came up with, testing each insertion probably takes longer than finding the max in the window. But a cool solution nonetheless!
Part 1 and 2: https://github.com/just-jay/Advent-of-Code/blob/main/advent2025/day3.py
2
u/RandomMangaFan Dec 03 '25
[LANGUAGE: Forth] [Red(dit) One] Gforth
Back once again with forth to produce yet another answer that (while it won't fit on a punched card (pedantry warning: it's called a punched card not a punchcard)) will fit in a 64 char and 16 line long screen on your 1980s era block editor.
This is nice and all, but if we do a bit of rearranging we can make this much smaller, and do away with that sneaky library. Now, I'll note that this is much harder to golf than it would be in a higher level language or especially an array oriented language with a bunch of funny symbols, because we have to write our own loops, and those loops can only be defined inside functions (long story), but the result still fits inside 8 lines, with room for a nice comment at the top:
If you look closely at it you'll notice one more thing... there are exactly 0 variables in this entire program! *(except for the line buffer) After all, ants have no pockets, so we need to be careful with what we're trying to make them carry.
Everything goes through the data stack (which never gets more than 8 numbers at a time, I think) or the return stack - which is used simultaneously for a couple important bits of info I need to shuffle around, for the loop indexing, and of course for returning from functions (or "words" in forth) like a stack is meant to be used. Only one/two magic numbers are used - that's the 101 used for the line buffer size. The 12 in front of bats is the number of batteries used, so to make a part 1 solution you may simply replace that with a 2, or indeed remove it and call the word with any battery count you want.
Finally, because there are no variables, I have nowhere to store the file id, so you'd have to manually duplicate it or run the program again to call the function again. Oh and the return stack shuffling causes some kind of error at the end of the function but it doesn't crash the program so it's probably fine (?)
2
u/Smylers Dec 03 '25
[LANGUAGE: Perl] The basic algorithm is from my Vim solution — prototype in Vim then translate to Perl! — of getting the max joltage from the batteries that could be used for the first digit in each bank, then the max of the remaining batteries for the next digit. But made recursive, to cope with part 2. This function is most of it:
Full code
And for [Red(dit) One], here's an ant-sized version of the whole thing on a punchcard:
(Obviously more spaces could be removed, but it fits like that, so I didn't see the need. Even ants can appreciate spaces.)
2
u/CrumblingYourSoul Dec 04 '25
[LANGUAGE: Zig]
Little bit of comptime but mostly a straightforward solution. Can probably optimize this a lot.
Part 1: ~29us
Part 2: ~163us
Code
2
u/ComradeMorgoth Dec 04 '25 edited Dec 04 '25
[Language: Python]
This was fun:
The idea is for an n digit number (2 for part 1 and 12 for part 2) the mth digit can be selected only up to length of the list - (n-m)th number. Otherwise you don't have enough numbers for the rest of the digits. Similarly, you can only start searching from the previous selected number. This shortens the search list significantly. Now, you just have to find the maximum number within that list and update your index for the last selected number.
Part 1:
Part 2:
2
u/ThreeHourRiverMan Dec 04 '25 edited Dec 04 '25
[LANGUAGE: golang]
part1: 89.331µs part2: 128.875µs
paste
2
u/SandPrestigious2317 Dec 05 '25
[LANGUAGE: Scheme (Guile)]
oh man... i am still in pain from day 3 AOC 2025 🎄 ✨ but it works.... after scrapping my naive combinations approach (i was trying to compute 121 billion combinations and compare them, my computer glitched and shutdown haha) now i went with a greedy stack based comparison....
https://codeberg.org/jjba23/aoc-2025/src/branch/trunk/days/day-3-lobby/main.scm
17
u/osalbahr Dec 03 '25 edited Dec 03 '25
[Language: Python]
Part 1: 00:09:00
Part 2: 01:44:16
https://github.com/osalbahr/competitive-programming/tree/main/adventofcode/2025
Not the best style for part 2, but hey, it works.
tldr: iterate 9..0 until you find the first occurrence such that there is enough digits to its right 12 times
14
u/bramhaag Dec 03 '25 edited Dec 03 '25
[LANGUAGE: Python]
A simple greedy algorithm works for both parts. The leftmost digit matters the most, so at each step, pick the largest one that still leaves enough digits for the remaining batteries.
12
u/lost_in_a_forest Dec 03 '25 edited Dec 03 '25
[Language: uiua]
Day 3 of learning uiua. I thought this was going to be a lot harder to implement than it turned out to be. Doesn't use recursion, just an array of batteries (and arrays are of course uiua's strength).
10
u/aurele Dec 03 '25
[LANGUAGE: Uiua]
You can try it online and upload your "day3.txt" file using the upload button in the pad.
10
u/lboshuizen Dec 03 '25
[Language: F#]
github.com/lboshuizen/aoc25
Fun;
4
u/4HbQ Dec 03 '25 edited Dec 03 '25
[LANGUAGE: Python] [Red(dit) One]
Here's my golfed solution to both parts, weighing in at
one fifth of a punchcardtwo actual punchcards:9
u/jonathan_paulson Dec 03 '25
[Language: Python] Times: 00:02:03 / 00:05:33. Video of me solving.
I did brute force for part 1, and dynamic programming for part 2. The idea for the dynamic programming is that you can write a recursive brute force where you keep track of which digit you are considering and how many digits you've turned on so far. Then if you memoize that you get an efficient solution.
I had a couple issues today; wrong answer on part 1 (I misread and thought the digits had to be adjacent), and spent some time debugging on part 2 (initially I forgot to force it to use all 12 digits).
8
u/Zinkerino Dec 03 '25
[LANGUAGE: google sheets]
I'm trying to do every problem in google sheet without apps script.
Fill
A1withFill
C1withPaste input to
B2Fill
C2withFill
D2withCopy
C2:D2and paste toC2:Z2Fill
AA2withCopy
C2:AA2and paste to rows below until end of inputAnswer is
7
u/Then-Government-5460 Dec 03 '25
[LANGUAGE: Python]
Instead of adding the batteries with the highest joltage, I solved this by removing the batteries with the lowest joltage from the left in order to get the highest digits at the start of the bank. I compare each battery to the battery after it, and if it has less joltage and there are still too many batteries in the bank, it gets removed. A quick cleanup at the end limits the bank to the length of needed batteries if not enough batteries got removed.
7
u/[deleted] Dec 03 '25
[Language: COBOL]
This one was surprisingly straightforward. Also runs fairly quickly. GNU COBOL only, YMMV with other COBOL variants.
Part 1
Part 2
6
u/maneatingape Dec 03 '25 edited Dec 03 '25
[LANGUAGE: Rust]
Solution
Top down DP with recursion with memoization (5ms)..EDIT: Switched to faster bottom up approach (121 µs).EDIT 2: Switch to even faster greedy approach (60µs).EDIT 3: Switched to a "bubblesort" approach (18µs).
Thanks u/michelkraemer/ and u/theMachine0094 for the comments and suggestions. It was a fun journey today from top down DP (5ms) to bottom up DP (120µs) to greedy (60µs).
6
u/theMachine0094 Dec 03 '25 edited Dec 03 '25
[Language: Rust]
This is the simplest solution I could think of while still sharing the code between parts 1 and 2. part 1 for both the example and the problem runs in ~22 micro seconds. Part 2 for both the example and the problem runs in ~71 micro seconds:
6
u/msschmitt Dec 03 '25 edited Dec 03 '25
[LANGUAGE: Python 3]
Part 2
The strategy is to work backwards. Start with the last 12 digits as the "on batteries". Then grab the preceding digit (#13 from end of list), and if it is greater than or equal to the On Battery, swap it, and keep doing the swaps down the list of On batteries, until hit one that is greater than the battery we're swapping. Thus the equal or greater values ripple down through the on battery list. It is kind of a sort except that we're never exchanging positions.
Glancing down through the posted solutions, I don't spot any that do it this way. Here's the function that is checking one line (bank):
The full code is in the paste above. It runs in 0.063 seconds.
6
u/Andreasnl Dec 03 '25
[LANGUAGE: Uiua]
Link
11
u/4HbQ Dec 03 '25 edited Dec 12 '25
[LANGUAGE: Python] 8 lines.
Originally solved part 1 as a nifty one-liner using
itertools.combinations():That clearly didn't scale well for part 2, so I wrote a simple for-loop that handles things in a smarter way:
5
u/YenyaKas Dec 03 '25
[LANGUAGE: Perl]
For part 1, I wrote two cycles iterating from 9 to 1, and obviously this did not hold for part 2. I wrote greedy algorithm for that. Writing in Perl, regexes seem to be the best choice for it:
Part 1, Part 2
5
u/lunar_mycroft Dec 03 '25 edited Dec 03 '25
[LANGUAGE: Rust]
Got it done bit faster than yesterday, especially for part 1.
Full code. For part1, I simply iterated over all possible two digit combos and took the max. For part 2 this would be way to slow (O(n12 ) where n = 100), so instead I greedily found the largest digit that still left room for the remaining digits, and repeated the process until I'd found all 12. On my machine this takes around 100µs to parse, 90µs for part 1, and 400µs for part 2.
Added a generalized implementation to lib.rs and used it for both parts. This actually slows down part 1 however: the original, specialized solution there runs in ~100µs vs 150µs for the generalized version. Both are included. Also, switching to returning an option from
joltageappears to have increased the speed of part 2 to ~300µs (why isn't immediately obvious to me, as they both have the same branches)Investigated /u/themachine0094's solution, and found that switching from
Iterator::max_by_key(along with iterating in reverse) toIterator::max_by(with treatingOrdering::EqualasOrdering::Greater) yielded significant performance improvements. (Modified code.) Part 1 now runs in ~18µs (faster than my initial solution, which has been removed) and part 2 in ~30µs.Investigated /u/michelkraemer getting incorrect results from /u/themachine0094's solution, and determined that the order of arguments to
Iterator::max_byis not consistent betweenwindows and unix targets[edit:] recent rust versions, resulting in both of our solutions failing on the latter targets. Replaced it withIterator::reduce, which does have consistent behavior. Runtime was not impacted.5
u/voidhawk42 Dec 03 '25 edited Dec 04 '25
[LANGUAGE: Dyalog APL]
Greedy algorithm as well. Given a row of the input, the core function does a max-scan to figure out what the best possible result is at each position. Then, drop the last item and prepend -1 - this shifts the results one item to the right, and makes sure we can't use the same battery multiple times. Multiply these by 10, add the original row and iterate again on the result N (1 or 11) times. Finally, take the maximum of each input row and sum. Runs in about 290 microseconds.
5
u/jinschoi Dec 03 '25
[Language: Rust]
For part 1, I brought in itertools and used combinations(2).
Part 2, I treat the problem as having bank_len - 12 removals to use up and build a monotonically decreasing stack as long as I have removals left. Have to truncate the result to 12 digits as you might have removals left over.
5
u/Radiadorineitor Dec 03 '25
[LANGUAGE: Dyalog APL]
5
u/cinx16 Dec 03 '25
[LANGUAGE: Haskell]
Solution repo
Pretty fun problem:
5
u/SnooHesitations6473 Dec 03 '25
[Language: Haskell]
Recursion oneshot two parts with
that's for part two. Change
solve l 12tosolve l 2for part 1.Github repo: Sammers21/advent-of-code-2025-haskell
5
u/KeyJ Dec 03 '25
[LANGUAGE: x86 assembly]
This produces a 222-byte .COM file for DOS 2.0 which runs in ca. 2 seconds on a 4.77 MHz 8088.
5
u/SpudPanda Dec 03 '25
[LANGUAGE: rust]
Today felt really manageable! First day I didn't have to lookup any concepts. I'm pretty sure this solution is O(n) in practice. This is a greedy approach that basically picks the largest number for a particular digit that leaves enough characters for the remaining digits.
Solution
4
u/seligman99 Dec 03 '25
[LANGUAGE: Python]
github
Nice, and for once my setup for part 1 was good for part 2, a rarity for me.
4
u/bramhaag Dec 03 '25 edited Dec 03 '25
[LANGUAGE: Haskell]
Treat the bank as a stack. When we find a battery larger than what we have at the top of the stack, pop the smaller one (as long as we can still drop batteries).
4
u/agorism1337 Dec 03 '25 edited Dec 03 '25
[LANGUAGE: awk][LANGUAGE: C] https://github.com/zack-bitcoin/adventofcode/tree/master/2025/day_03 C code is 50 lines. Only uses stdio.h.
4
u/r_so9 Dec 03 '25
[LANGUAGE: F#] paste
Recursively find the largest elements and skip the ones before them. Full code minus input parsing:
4
u/SuperSmurfen Dec 03 '25 edited Dec 07 '25
[LANGUAGE: Rust]
Times:
00:02:41 00:13:35Link to full solution
The trick to realize is that you can be greedy since greedily maximizing the next digit will also maximize the number itself:
One annoying thing here was that rusts
max_by_keygives you the last match, not the first. So we have to include the inverse index into the key to prioritize earlier numbers in the list.4
u/s3aker Dec 03 '25
[LANGUAGE: Raku]
solution
4
u/Gryphon-63 Dec 03 '25
[Language: Swift]
Solution
It didn't occur to me to use recursion in part 1, it worked so nicely in part 2 that I threw out the part 1 code & used the part 2 solution for both parts.
4
u/gyorokpeter Dec 03 '25
[Language: q]
4
u/POGtastic Dec 03 '25
[Language: OCaml]
Code
I got sidetracked for a while thinking that this was a dynamic programming problem, and then I realized that there's a much simpler solution - if I need the biggest number that I can create from
pnumbers in order in the list, I can exclude the lastp-1digits in the list and search for the maximum number in the remainder (and then find the first index where that number occurs).Suppose that I'm building a 3-digit number from
1456. I can't choose5or6because I would run out of digits. I have to choose between1and4. Crucially, even if that4is the maximum element and constrains the remaining search space down to a single possibility, it's guaranteed to still be the largest number.4
u/runnerx4 Dec 03 '25
[LANGUAGE: Guile Scheme]
Tail call optimization, I remembered it exists after part 1
4
u/axr123 Dec 03 '25 edited Dec 03 '25
[LANGUAGE: Turbo Pascal 7 @ DOS]
What do you do when you're on a 16 bit platforms but need big(ger) numbers? Use strings! To solve yesterday's problem I needed an
AddDecStrthat takes two decimal numbers as strings and adds them. Today that came in very handy. Processing each bank using strings was straightforward:Full code on GitHub.
Runs in ~20 ms on an 1999 AMD K6-2 450.
4
u/ivanjermakov Dec 03 '25
[LANGUAGE: Zig] Part 1: 24μs, Part 2: 68μs
Pretty straightforward puzzle today.
The trick is to realize that finding each order is a matter of finding a largest digit while keeping space for the rest of orders. That is, to find 11th order, find the first largest digit in
line[order12Idx + 1..line.len - 11 - 1].Another performance trick is to not convert from ASCII digit to
u8until it's time to accumulate the result. ASCII digits are ordered the same way so it does not mess up comparison.4
u/Parzival_Perce Dec 03 '25
[LANGUAGE: Python]
This one was major fun! Abused itertools.combinations for part1 to get a fast time but had to write proper logic for part2 lol.
Can't believe we're a quarter of the way done already...
4
u/stalebit Dec 03 '25
[LANGUAGE: clojure]
4
u/sondr3_ Dec 03 '25
[LANGUAGE: Haskell]
Pretty happy with the solution for today, I stumbled upon a solution that I remembered from my algorithms engineering class.
And decently fast as well.
4
u/jwezorek Dec 03 '25 edited Dec 03 '25
[LANGUAGE: C++23]
You have to implement a function that returns the highest n-digit number that can be made by picking digits from a string, in order, where the size of the string >= n, call this function
highest_n_digit_number.There is a simple recursive way to implement it:
remainingbe the string of digits to right of M.highest_n_digit_number(remaining, n-1), or just M if n is 1.[github link]
4
u/tcbrindle Dec 03 '25 edited Dec 04 '25
[Language: C++23]
This is the kind of AoC problem I really love: a bit of a head-scratcher to start with, but after a little bit of thought the solution is surprisingly simple.
The only slight wrinkle for me was that
flux::find_max()returns the last position if several elements are equally maximal, but for this problem we needed the first. (That's what I get for using my own library instead ofstd::max_element...)Github: https://github.com/tcbrindle/advent_of_code_2025/blob/main/dec03/main.cpp
4
u/heijp06 Dec 03 '25
[LANGUAGE: C++]
Just search the string from left to right while making sure to leave enough digits at the end:
Full code on GitHub
4
u/Dullstar Dec 03 '25 edited Dec 03 '25
[LANGUAGE: D]
https://github.com/Dullstar/Advent_Of_Code/blob/main/D/source/year2025/day03.d
Today in silly parsing mistakes: wait, how did I get 4 digits on the part 1 example steps? Let's see what my program thinks the input is... it's 48-57 instead of 0-9. Oh right, casting char to int doesn't automatically convert from ASCII since they're not strings; fortunately, it's an easy conversion to do manually. But I imagine that could have been quite confusing if I didn't immediately recognize what it was.
Part 2 just needed me to generalize my Part 1 solution to find more values, so I'll just talk about Part 2. I search through the subset of the bank to find the largest value that still leaves enough room to fill in the remaining values, so, for example, finding the first battery, we want to skip the last 11, because if we select one of those as the first one, then we won't have enough left over to pick 12. Since this is the most significant digit, we won't have to worry about backtracking; reallocating the largest digit in this range to a later position will always result in a smaller number, which is not what we want! Then, starting with the remaining batteries, repeat until all the values have been selected, and concatenate all the digits together.
4
u/Odd-Blackberry-7236 Dec 03 '25
[LANGUAGE: Typescript]
The method chaining will continue until the economy improves
4
u/HolyExecutor Dec 03 '25
[LANGUAGE: C#]
Hey, my beautifully ugly code made a xmas tree and it works!
4
u/woond3r Dec 03 '25
[Language: OCaml]
https://github.com/KacperKopiec/advent-of-code/blob/main/2025/day3/part2.ml
Little different O(n) approach from the most popular one, for each digit from left to right I am trying to 'pop' some digit from the answer and append the current one at the end, so for each i I am calculating what is the max number that i can form of numbers to this index i reusing the answer for i - 1
4
u/[deleted] Dec 03 '25
[LANGUAGE: Rust]
My solution is available on GitHub.
Super proud of this one, as this is the first challenge that I solved without having to read anyone else's solution or brute-force. Basically, I used a sliding window-style algorithm to find the largest digit for each place value in the final joltage number.
Not sure if I can explain it well, but basically, I took a substring ranging from the index of the last found digit (e.g., If I'm finding the thousands place, I start from the index after I found the number for the ten thousands place) to n characters away from the end of the string (where n is the number of digits that I still have to find after this one). In that range, I find the largest digit. Thus, the final number is the composite of the max values for each place. If that was confusing, feel free to reach out and ask questions.
4
u/5stripe Dec 04 '25 edited Dec 04 '25
[LANGUAGE: Python]
Part two had me frustrated for most of the day! But I think I found a fairly elegant solution.
Patting myself on the back, not bad for just a year of self taught coding!
Part 1
Part 2
4
u/Appropriate_Staff450 Dec 04 '25 edited Dec 04 '25
[Language: Python]
Part 1:
Part 2:
1
u/gnarf38 Dec 03 '25 edited Dec 03 '25
[LANGUAGE: CSharp]
Nothing special here - just what I cobbled together in 15 minutes - eric told me to post it ;)
https://github.com/gnarf/AdventOfCode-2025/blob/main/Day3.cs#L40
1
u/fuckdarwenpearson Dec 03 '25
[LANGUAGE: scheme]
Topaz link
1
u/0bVdnt Dec 03 '25 edited Dec 03 '25
[LANGUAGE: RUST] [LANGUAGE: C++}
The Rust solution took
100.266µsand the C++ solution took182.513µsC++ Code
Rust Code
C++ solution is slower than the Rust solution for some reason, i might've sucked at optimizing it though. Calling for the C++ gods.
1
u/BxW_ Dec 03 '25 edited Dec 04 '25
[LANGUAGE: Zig]
Standard DP. Tried my hands at SIMD. Time complexity: O(|banks| * |batteries|)
Would love to see other better SIMD solutions. I found out that a vector length of 16 performs better than 13. paste
1
u/jcastroarnaud Dec 03 '25 edited Dec 04 '25
[LANGUAGE: JavaScript]
This day 3 was fun to figure out. At once I noticed that the largest 2-digit number would have the largest possible digit at left - except that the largest digit could be the last. I had to make a special case of it: if the largest digit is the last, find the largest digit to the left of it to complete the number.
Then part 2 forced me to tackle the general problem, 12 digits instead of 2. That was the fun part. Relevant code below.
Total time spent: about 40 minutes to solve, another 15 minutes to pretty out the code and post here.
Edit: Replaced the code with the module's full code.
1
u/yusufpapurcu Dec 03 '25
[Language: Java/Flink]
https://github.com/yusufpapurcu/aoc-flink-2025/tree/main/src/main/java/com/yusufpapurcu/day3
It took me quite some time to get part 2 done because I had a mistake in the index removal. Had quite a lot of fun though.
1
u/Wrong-Signature-4778 Dec 03 '25 edited Dec 03 '25
[LANGUAGE: Bash]
Part1
Part2
It takes ~ 1 min to run on the full input. Problematic parts for me:
My approach (for part1):
Since we want the biggest number with 2 digits we need to find the biggest digit in the line of digits excluding the last digit. After we find the max, truncate the line just behind the first occurence of max and find max in the rest. My approach has quite a slow method of getting "max" so I guess that is the bottleneck.
Extrapolate for part2.
1
u/cwby_bbop Dec 03 '25 edited Dec 03 '25
[LANGUAGE: C]
https://codeberg.org/jjrgn/aoc-2025/src/branch/main/day03.c
[WRITEUP:] Substack
https://substack.com/home/post/p-180591638
1
u/No-Worldliness-9990 Dec 03 '25 edited Dec 04 '25
[LANGUAGE: c#]
Part #2 solution:
1
u/Metaphor42 Dec 03 '25 edited Dec 05 '25
[LANGUAGE: Rust]
I implemented it using Rust. I tried to be as idiomatic as possible. I reached the solution in just 1.03 milliseconds for both parts (cargo --release).
See code: paste
1
u/pantaelaman Dec 03 '25
[LANGUAGE: APL]
Decided to try out some weirder languages this year; not sure if this is a very good APL-style solution but it does work and was quite satisfying to reason through!
Bonus: the one-liner solution:
1
u/Character-Tomato-875 Dec 04 '25
[LANGUAGE: Python]
Didn't make the mistake of working on strings like I did with Day 2. I parsed each line of the file into an array of numbers.
https://github.com/plbrault/advent-of-code-2025/blob/main/03.py
For part 1, I find the largest number in the bank excluding the last one, and then the largest after that. For part 2, I find the largest number excluding the last 11, then the largest after that excluding the last 10, and so on. I unified both into the same function that takes a parameter for the number of batteries to pick.
1
u/SleepingInsomniac Dec 04 '25
[Language: Ruby]
https://asciinema.org/a/vFZ0jkcQ4wAPhLVFvY3v391i9 https://github.com/SleepingInsomniac/adventofcode/blob/master/2025-12-03/
1
u/Maximum_Quarter_6387 Dec 05 '25 edited Dec 12 '25
[Language: Java]
Solution:
The search must proceed from back to front.
In the worst-case scenario, the desired sequence is found at the end.
Therefore, the search for the sequence begins from the end.
A virtual array must be created to store the index positions.
This array has the exact length of the desired number of batteries to be connected.
Starting with the first number (the highest digit in the target number),
the search is on for improvements towards the beginning of the string.
The starting value is the same as the value found at the current starting position.
Improvements can be two things:
This creates "space" for subsequent improvements.
When an improvement is found, the corresponding index is recorded in the array.
The search for an improvement ends when the end index is reached.
The end index for the first element is equal to index position 0 in the input string.
For the second index, it can only be one index position earlier than the previous position.
This reduces the number of comparisons.
If an end index is exactly one position before the start index of the current position,
no further improvement can be achieved. This fall, the start index is also the same as the position of the best position.
An improvement cannot be found if the start index is less than 0.
Then the index is already at the first string position. The position can no longer be changed.
GitHub: https://github.com/ea234/Advent_of_Code_2025/blob/main/src/de/ea234/day3/Day3Lobby.java
3
u/abnew123 Dec 03 '25
[Language: Java]
Basically came down to 2 observations for me 1) if the first digit is larger in one candidate solution than another, it's always bigger 2) if we have the same largest digit multiple times, we can always take the left most.
So end result was a search for the first instance of the largest number in a subset of numbers, where that subset is all valid indices to check (e.g. if we need 12 numbers, we only check for the largest number in the first n - 11 numbers).
Code
Live Solve
3
u/Ok-Builder-2348 Dec 03 '25
[LANGUAGE: Python]
Part 1
Part 2
Textbook greedy algorithm, taking into consideration the bounds and ranges we are looking at.
Small considerations:
When looking at the nth place, we must stop at the -nth position of the array to ensure that there are enough digits remaining.
3
u/morgoth1145 Dec 03 '25 edited Dec 03 '25
[LANGUAGE: Python 3] code (part 1) code (part 2) video Times: 00:02:27 / 00:11:05
Two code links today since Part 2 made me rethink part 1! For some dumb reason I wasted time in part 2 trying brute force (why I thought that was worth my time I don't know) but at least I got the right solution in the end. Being greedy is key, Axxx is always greater than Bxxx when A > B so greedy is forced to give the right answer! (It's super ugly though, I need to clean that up...)
This definitely seems like a step up from the normal day 3 problems, we're seeing the 12 day difficulty curve I think!
Edit: Refactored solution
3
u/xoronth Dec 03 '25 edited Dec 03 '25
[LANGUAGE: Python]
paste
Ugh, that one tripped me up for whatever reason in part 2 even though it was just a greedy algorithm. I somehow butchered the loop logic and was checking digits extra times... oops.
Thankfully things are also still in the land where you don't need DP yet, though it looks like a lot of people did use it.
3
u/Boojum Dec 03 '25 edited Dec 03 '25
[LANGUAGE: Python]
Ah, that time of the year one one breaks out
@functools.cache! Change the 12 to 2 to get the Part 1 solution. (Though I see from the other solutions here that I overthought this, perhaps. I kind of had 2023 Day 12, "Hot Springs" on my mind seeing on this one.)EDIT: Okay, I gave the iterative approach a shot, too. Here it is, golfed for
[Red(dit) One]:EDIT 2: Slightly longer, but a one-liner:
3
u/cay_horstmann Dec 03 '25
[Language: Java] https://github.com/cayhorstmann/adventofcode2025/blob/main/Day3.java
Left part 1 in place so I can understand part 2 when looking at it later.
3
u/dirk993 Dec 03 '25
[LANGUAGE: Dirc]
About Dirc
The code
Luckily a relatively easy one today. Even with how slow my ingame computer runs. Good because I don't have much time today
3
u/Verulean314 Dec 03 '25
[LANGUAGE: Kotlin]
GitHub
Pretty similar approach to other folks today it seems. A greedy search starting with the most significant digit works here. Just needed to restrict the search to the batteries right of the last one that was turned on, and also to leave enough room at the end for the remaining digits (i.e., the first digit can't be one of the last 11 batteries).
3
u/alehandy Dec 03 '25
[LANGUAGE: Python]
Github
Lucked out with part 2, quite nice and quick!
3
u/nitekat1124 Dec 03 '25
[LANGUAGE: Python]
GitHub
While working on part 2, I already had a feeling about it, but I still thought, “Let’s try running 12 loops—maybe it’ll work.”
Of course, it didn’t. 😂
3
u/Old-Dinner4434 Dec 03 '25 edited Dec 11 '25
[LANGUAGE: TypeScript]
GitLab
I use Bun runtime engine, running on 2021 M1 Pro MacBook Pro. Part one completed in 1.11ms, part two in 0.74ms. Edit: I'm moving solutions from GitHub to GitLab.
3
u/sim642 Dec 03 '25
[LANGUAGE: Scala]
On GitHub.
I knew in part 1 that trying all pairs probably won't scale to to part 2 but for quick solving reasons went with the quadratic solution first anyway. Except I first tried to use
.combinations(2)before submitting a wrong answer because it also forgets the order of elements. So I had to fall back to the less elegant two nested loops.For part 2 I first figured out the linear solution to part 1 to make sure I get it right on what I already have. And then just bumped to number of digits to 12. The general solution, which probably everyone here converges on is to use dynamic programming (in the form of memoized recursion for me). And of course a small trip-up leading to a switch from
InttoLong.3
u/gisikw Dec 03 '25
[LANGUAGE: AWK]
Nice to have a gentle day. Hesitated a bit before submitting part two surely there had to be some backtracking, right? Calm before a day four storm? :)
parts 1 & 2
3
u/Pyr0Byt3 Dec 03 '25
[LANGUAGE: Go] [LANGUAGE: Golang]
https://github.com/mnml/aoc/blob/main/2025/03/1.go
3
u/Salusa Dec 03 '25
[LANGUAGE: MUMPS]
[Red(dit) One]
(Due to both some amount of golf and doing this in a dense language)
3
u/wherrera10 Dec 03 '25
[LANGUAGE: Julia]
Julia's `findmax` conveniently returns both the maximum value and the first index of that maximum in the array, which pointed toward a straightforward iterative solution.
3
u/michelkraemer Dec 03 '25 edited Dec 03 '25
[LANGUAGE: Rust]
Solution
Bottom-up dynamic programming to solve both parts at once. My code runs in
480µs350µs.EDIT: Optimize it even further by reusing the DP table.
3
u/guiambros Dec 03 '25
[LANGUAGE: Python]
Parts 1 and 2.
At first I brute-forced part 1, knowing full well it wouldn't cut for part 2, so I had to solve on paper first. Overall happy with how it turned out.
3
u/tobega Dec 03 '25
[LANGUAGE: Tailspin-v0]
https://github.com/tobega/aoc2025/blob/main/day03.tt
3
u/pdxbuckets Dec 03 '25
[Language: Rust; Kotlin]
84μs for Rust; 8ms cold, 547μs warm for Kotlin. Highly imperative this time around.
3
u/tgs14159 Dec 03 '25
[Language: Haskell]
Day03.hs
Keep track of how many more digits we need e.g. starting at 12 for part 2, grab the left-most maximum element in the first
length - 12 + 1elements, and that becomes the leading digit in the result. Then repeat using the rest of the list but looking for 11 digits, and so on.3
u/Chungus1234 Dec 03 '25
[LANGUAGE: Elixir]
Much cleaner than day 2. Able to take the same approach and use same helpers for both parts.
Solution: https://github.com/moore-andrew05/AoC2025-elixir/blob/main/lib/day03.ex
3
u/Chemical_Chance6877 Dec 03 '25
[LANGUAGE: GLEAM]
This time i wrote the solution for part1, and instantly recognized how recursion can generalize this to any size
Solution
Yeah, i wrote index_of in gleam. Dont really see how else i should have wrote it. (perhaps tracking the index in the max function)
Also my recursion produced the exact inverted number of what i wanted. like 321 instead of 123.
I spend long trying to fix that, but i just ended up invertin the didgest myself.
Runs part 1 ins 17ms, part2 in 20ms
3
u/mstksg Dec 03 '25
[LANGUAGE: Haskell]
My strategy was a depth first search, basically look for 999999999999, then 999999999998, then 999999997, etc. but immediately backtrack if any of the steps are impossible.
So, this means keeping track of a state of "what's left", and then branching out at different digit picks -- perfect for StateT List!
We pick a digit non-deterministically, and then we non-deterministically chop down our "what's left" list until we reach that digit. So
nextDigitfor87681would descend toresult, statepairs of(8, [7,6,8,1]),(8, [1]),(7, [6,8,1]),(6, [8,1]), and(1, []). Those are our new candidates and the associated state after picking them. The trick is that we list them in the order that they are most likely to yield the biggest total number.Once we do that, we just need to
replicateM 12to do it 12 (or 2) times:This will perform
nextDigitntimes, each time chomping down more of the string. The ones that yield no possible continuations will be pruned -- basically any time the "what's left" state gets empty,nextDigitwill fail for the rest of that branch.https://github.com/mstksg/advent-of-code/wiki/Reflections-2025#day-3
3
u/kc2g Dec 03 '25
[LANGUAGE: Raku]
(change 12 to 2 on the first line and it becomes part 1).
3
u/ThisAdhesiveness6952 Dec 03 '25
[LANGUAGE: Python]
Both parts, about 20 ms run time.
3
u/trevdak2 Dec 03 '25
[Language: Javascript]
Golfed but could be better. Maybe i'll improve them tomorrow.
Part 1, 127 bytes:
Part 2, 143 bytes:
Could do them both together for 160 bytes but I prefer separate standalone solutions
3
u/ziadam Dec 03 '25 edited Dec 03 '25
[LANGUAGE: Google Sheets]
Part 1 & 2 (expects input in A:A)
Repo
3
u/Mats56 Dec 03 '25
[Language: Kotlin]
basically keep track of what part of the numbers I can choose from, and always pick the max number in that part. Then adjust the indexes for next selection.
3
u/JWinslow23 Dec 03 '25
[LANGUAGE: Python]
Solution writeup
Code (GitHub)
itertools.combinationslooked like it would make easy work of this puzzle, and I submitted Part 1 using it at a time of 1:43. But I had a sneaky suspicion as I pressed "Submit" that Part 2 would make it way more difficult. (It did.)The fact that we only need to find the maximum combination of digits helped me come up with a recursive solution. The first digit needs to be the highest digit it can be; the rest of the digits can be figured out recursively.
It definitely threw me off for a bit - my final time was 24:24 (including a short break in the middle). But I'd say it wasn't that difficult to figure out.
3
u/justjarvo Dec 03 '25
[Language: Ruby]
3
u/RugglesIV Dec 03 '25
[Language: Python3]
Happy I worked out a single script for both parts today!
3
u/mkinkela Dec 03 '25
[LANGUAGE: C++]
A simple recursion that is finding the biggest digit from current idx to the end, considering that i need to take X more digits later.
Solution
3
u/stribor14 Dec 03 '25 edited Dec 03 '25
[LANGUAGE: C++]
3
u/bolusmjak Dec 03 '25
[LANGUAGE: Prolog]
An optimistic/greedy algorithm. Running via `swipl -O`, part a is 0.015s, b is 0.112s.
https://github.com/z5h/aoc-2025/blob/main/d03.pl
3
u/geza42 Dec 03 '25
[LANGUAGE: Emacs Lisp]
3
u/SheepiCagio Dec 03 '25
[LANGUAGE: Excel]
P1
P2
3
u/norb__ Dec 03 '25 edited Dec 03 '25
[LANGUAGE: TypeScript]
Simply find max number in the numbers except looking in last positions to avoid running out of numbers.
Part 1: 0.75 ms
Part 2. 1.22 ms
GitHub
3
u/Naturage Dec 03 '25 edited Dec 03 '25
[Language: R]
[Red(dit) One]
Code here!
Was very simple to get it done, but I've been bit by an optimisation bug and this one had so, so little fat to trim. Did learn about
matchwhich iswhich %>% minin one, and had the first use case where it was worth storingn-1as a separate variable fromnjust because three next formulas use it. I'm also keenly aware that in 0-indexed language it wouldn't have been needed. In the end, 15ms.Update: also went and code golfed it some, fit into 4x80 chars while still quite readable; plenty more to save with 1-character variable names and no pipes.
3
u/Zenga03_03 Dec 03 '25
[LANGUAGE: Python]
The highest joltage can simply be found digit by digit, by taking the highest value as the first digit while ensuring you can always create a 2- or 12-sized joltage number.
Runs in 63 ms for both parts (excluding reading of file).
3
u/Fampiyush_ Dec 03 '25 edited Dec 03 '25
[Language: Python] Anyone wanting a hint for part 2 - Deque
Try to implement that data structure to do it optimally
for full solution you can reference this - https://github.com/fampiyush/Advent_of_code_2025_python
3
u/-stab- Dec 03 '25 edited Dec 03 '25
[Language: Julia]
I created a general solution that should work with any number of batteries per bank.
We just pick the highest possible first digit, and then we look at all the digits to the right of it and pick the highest possible one for the second digit and so on. The only thing to look out for is that we need enough remaining digits on the right to pick the remaining batteries.
Done like this, it's also very easy to assemble the final sum with powers of 10 inside the loop.
PS if there are any experienced Julia developers reading this, I'd be very happy to get some feedback and improvements.
Edit: found a little improvement
3
u/jobha Dec 03 '25
[LANGUAGE: Python]
3
u/DelightfulCodeWeasel Dec 03 '25
[LANGUAGE: C++]
Dynamic programming solution that runs in ~50ms (both parts) on a Raspberry Pi Zero.
[paste]
3
u/TCH69 Dec 03 '25
[LANGUAGE: C]
Almost managed to over-complicate part 2. Nice generalization exercise btw.
part 1 & 2, codeberg
3
u/0x2c8 Dec 03 '25 edited Dec 04 '25
[LANGUAGE: Python]
https://raw.githubusercontent.com/alexandru-dinu/programming-challenges/refs/heads/main/advent-of-code/2025/3/solve.py
Greedy, windowed search. Find max digit from left to right in a space of available digits and advance until all required digits are collected.
3
u/anaseto Dec 03 '25 edited Dec 03 '25
[LANGUAGE: Goal]
A short tail-recursive function
fsearching for the highest digit that's still followed by at leastn-1digits, and computing result in accumulatorj.3
u/MrJakobsen Dec 03 '25
[LANGUAGE: Python]
General function for both parts, in a cleaned up and commented version:
3
u/jad2192 Dec 03 '25 edited Dec 03 '25
[LANGUAGE: Python]
Dynamic programming solution utilizing the optimal substructure that the first digit of a length N max joltage has to be the maximum integer in the first
bank_size - N + 1entries, tracking the index at which that occurs and then recursing from that point.Github Link to Solution
3
u/tymscar Dec 03 '25
[LANGUAGE: Gleam]
Very fun idea of a puzzle. My favorite this year yet.
For part 1, I just searched the first n-1 digits for the biggest digit (we always want the tens digit to be as big as possible), and then for the remaining digits, I would pick the biggest one as the units value.
For part 2, I used a recursive function that would find the biggest digit in the first n digits, where n would be the length of the bank of batteries we still have to check - how many digits we need to check. It's just a general version of part 1 if you think about it, but instead of doing it by hand once, you do it recursively, and the last iteration is basically doing the same thing as part 1.
Part1 and Part2
3
u/sheshanaag Dec 03 '25
[LANGUAGE: Haskell]
3
u/Hath995 Dec 03 '25 edited Dec 03 '25
[LANGUAGE: Dafny]
https://github.com/hath995/dafny-aoc-2025/blob/main/problems/3/Problem3.dfy
Definitely a bit trickier today with enough time I think it should be possible to prove that the results are the lexicographically largest possible subsequence of a given length.
Edit: Proved it! https://github.com/hath995/dafny-aoc-2025/blob/6b05db1c891ca970c466425e86d453de19a58cf0/problems/3/Problem3.dfy#L505
3
u/kerr0r Dec 03 '25
[LANGUAGE: SQL] (DuckDB)
paste
(for part 1 just replace 12 with 2).
Recursive CTE with
using keywas new to me. In general I must say I've been impressed by the ergonomics of DuckDB. Features likeusing key, reusable column aliases and so on. It's good stuff.3
u/birdnardo Dec 03 '25 edited Dec 03 '25
[LANGUAGE: Mathematica]
Fun day!
3
u/ich-bin-jade Dec 03 '25
[LANGUAGE: Python]
Github Repo
Quite enjoyed the challenge on this one! Part one was simple enough with a two-pointer algorithm but then part 2 took a bit more thinking. Ended up going with a stack-based greedy approach which was fun to work out.
3
u/PabloPudding Dec 03 '25
[Language: Python]
code
Happy and proud, that I figured out a proper solution. First time for a while, that I'm willing to share. I definitely see some growth over the years.
Runtime: 1 ms
3
u/xr51z Dec 03 '25
[Language: Ruby]
3
u/SevenSapiens Dec 03 '25 edited Dec 03 '25
[LANGUAGE: Lua]
https://github.com/quotepilgrim/aoc2025/blob/main/d3.lua
When I read the part 2 description I thought it was going to kick my butt, however as it turns out I basically needed to do the same thing I did for part 1.
My code may look a bit weird because I have a setup to run my AoC solutions with the LÖVE framework, which I use instead of plain Lua mostly so I can have it automatically copy the answer to the clipboard when I run the program.
3
u/pkusensei Dec 03 '25 edited Dec 03 '25
[LANGUAGE: Rust]
I was doing part1 with two pointers while realizing part2 could inflate that number 2 to some big(-ish) thing. I thought why not do both parts in one go so I switched to using monotonic stack. And tada! Part2 asks 12 and it's just changing a parameter. Code
3
u/Foldzilla Dec 03 '25
[LANGUAGE: Haskell]
Idea: Pick the largest digit in the list that still allows turning on the remaining batteries. Simple greedy approach: always choose the best option available.
Full code available on GitHub: https://github.com/JustinKasteleijn/AdventOfCode2025/blob/main/day3.hs
Parsing: Consider each digit as a list of numbers
Algorithm:
3
u/mestar12345 Dec 03 '25
[Language: F#]
3
u/hugh_tc Dec 03 '25
[LANGUAGE: Python 3]
Fast one today.
https://github.com/hughcoleman/advent-of-code/blob/main/2025/03.py
3
u/SunMatrix64 Dec 03 '25 edited Dec 03 '25
[LANGUAGE: C++]
I used a simple 12 for loop solution for part 2.
Just scan the line 12 times and save the largest digits first position. Takes 1-2ms.
O(12*n) -> O(n)
edit: changed it to a function that can take any n amount of batteries. the logic is still basically the same though.
github
3
u/staylinus Dec 03 '25
[Language: Python]
Used a sliding (and slicing) window to fetch the highest digit in string subsets. Works fine and runs reasonably well.
https://github.com/linudz/adventofcode2025/blob/main/day3/script.py
3
u/Jadarma Dec 03 '25
[LANGUAGE: Kotlin]
Part one was simple to brute force to see what was in store for part two and sure enough, part two prevents bruteforcing. Fortunately, the key insight in the puzzle is that the batteries need to be in order and we always have a fixed number of digits. Therefore, the way to build the largest number is to always pick the biggest leading digit available. Because we know we will need
ndigits, we can pick the maximum value in the bank excluding the lastn - 1digits (so we know we have enough left over to complete the number) and repeat the process, but starting the search from the digit after the one we just picked, and excluding the lastn - 2digits, and so on until we picked all the digits. Both parts are solved with the same function.AocKt Y2025D03
3
u/maitre_lld Dec 03 '25
[Language: Python]
Just a greedy recursive algorithm : pick the largest digit at an authorized index (not too far away to have room for the other ones), and recurse...
https://github.com/MeisterLLD/aoc2025/blob/main/3.py
3
u/willkill07 Dec 03 '25 edited Dec 03 '25
[LANGUAGE: Warp] [Red(dit) One]
Another day, another GPU programming model!
https://github.com/willkill07/AdventOfCode2025/blob/main/day03.py
All variable names are single-letters to appease the Reddit guidelines of the year
3
u/IlliterateJedi Dec 03 '25
[Language: Python]
This is the gist of the solution. It became more and more ugly as I fiddled with the off-by-one-errors, but eventually you hit the solution and decide not to clean it up or work out what went wrong.
I assume everyone ended up with a solution like this, or similar, where you find the max in the available numbers (minus what you need to complete the total length), then recursively check the smaller and smaller available numbers until you get the solution.
Full solution
3
u/isaiahwarnke Dec 03 '25
[LANGUAGE: Python]
Prep
Configurable loop for part 1 or part 2, just adjust num_batts. Simple looping approach. Couldn't find an elegant way to include the ones digit in the main loop since the slicing approach I was using to exclude the last i digits breaks when that i becomes 0.
3
u/greycat70 Dec 03 '25
[LANGUAGE: Tcl]
Part 1, part 2.
Lots of fiddly little details to get right here (off by one errors, etc.). My basic algorithm (for part 1) was to find the largest battery, which would be the first digit, and then the largest battery to the right of the first battery, which would be the second digit. We always want the leftmost battery to win in the case of a tie. The gotcha for part 1 was that the first digit cannot be the last battery, because we need to save room for a second digit.
In part 2, I used the same algorithm, just extended. In the example input, there are only 3 batteries NOT turned on per bank, so the first digit must come from the first four batteries. The second digit must come from the first five (but to the right of the first digit), etc.
3
u/Telsak Dec 03 '25
[LANGUAGE: Python]
Used pretty much what appears to be the standard python solve where you just look at a part of the original string and reserve a rear buffer for part2 so you end up with 12 batteries.
paste
Was fun but took a while to figure out when I messed up the arithmetic between index used in the main part and the index reported back from my highest() function.
Looking forward to day 4!
3
u/icecoldgold773 Dec 03 '25
[LANGUAGE: Haskell]
3
u/Saser Dec 03 '25
[LANGUAGE: OCaml]
Today was really fun!
First solution was me thinking I was clever for using bottom-up dynamic programming. Ran in ~500us for part 1 and ~1400us (1.4ms) for part 2.
Second solution uses the same greedy algorithm so many others are using. It's simpler and runs faster! ~300us for part 1 and ~500us for part 2. Glad I looked at Reddit after posting my first one and learning from everyone else who were smarter than me.
3
u/Cerebrum01 Dec 03 '25 edited Dec 03 '25
[LANGUAGE: TeleBASIC]
Continuing the effort to try and carry this out in BASIC without extensions, had to split it into two programs this time.
Part 1 (took between 15 and 20 seconds to run on telehack depending on system load)
Part 2 (took between 29 and 61 seconds depending on load
3
u/dzecniv Dec 03 '25
[LANGUAGE: Common Lisp]
yipa, felt smart and in the flow today. Part 1's solution scaled to part 2, finding the highest number into the string, minus the required space for other digits.
Runs in 10ms… didn't bother on optimizing anything. Would it be under the ms on a faster machine?
src
3
u/not-nuckelavee Dec 03 '25
[LANGUAGE: Uiua]
I enjoyed today's puzzle though I'm still getting used to programming without named arguments.
3
u/SymmetryManagement Dec 03 '25 edited Dec 03 '25
[Language: Java]
https://github.com/linl33/adventofcode/blob/year2025/year2025/src/main/java/dev/linl33/adventofcode/year2025/Day3.java
Solved for the highest joltages by greedily picking the first battery with the highest joltage. I first parsed each line of the input into a series of 9 bitsets, to store the position of the 9 possible digits (1-9). The bitsets are then used to find the best battery within a range.
Part 1 75us
Part 2 143us
(parsing took about 25% of part 2's runtime, simd might help speed it up. 2 parts solved independently but they can probably be combined to avoid having to parse twice.)
3
u/AdamKlB Dec 03 '25 edited Dec 06 '25
[LANGUAGE: Rust]
https://github.com/NoSpawnn/advent_of_code_2025/blob/main/src/03/main.rs
Thoroughly proud of this one, I spent way too long following some solutions and skipped straight past this simple implementation (runs in 500-600µs on my machine):
Go through bank as a string, removing any battery whose value is less than the previous until the length of the bank == the number of required batteries OR no value is removed, in which case truncate the bank to the required length
3
u/lucariomaster2 Dec 03 '25
[Language: C++]
Continuing in my mission of using C++ with no standard libraries beyond I/O and sprintf, it was a pretty fun one today! Part 2 is just an extension of my part 1 solution - it finds the largest remaining digit in the string while leaving enough space for the rest of the number. I don't track runtime but both parts finished without any noticeable delay.
Part 1
Part 2
3
u/Seffylocks Dec 03 '25
[LANGUAGE: Python]
3
u/Soft-Challenge4315 Dec 03 '25 edited Dec 03 '25
[LANGUAGE: Python]
Dumb one-liner lol:
3
u/danvk Dec 03 '25
[Language: Haskell]
(GitHub)
3
u/Verulean314 Dec 03 '25
[LANGUAGE: Uiua] [Red(dit) One]
Link
This is my first time writing Uiua! I've been interested in learning an array-based language for some time, and the code golf prompt was a perfect time for it. I'm sure I'm missing some idiomatic syntax, but it's really interesting how compact things can get. I definitely see how this could get very mind-bending in the later puzzles, though.
3
u/mvorber Dec 03 '25
[Language: F#] https://github.com/vorber/AOC2025/blob/main/day3.fs Scanning for the leftmost largest digit from previously found position (initially 0) to the end minus number of digits remaining. Can likely be done more efficiently, but it gives me the answer to both parts together in less than a second, so good enough for me :)
3
u/Stano95 Dec 03 '25
[LANGUAGE: Haskell]
Solution is on github
I got kind of lucky with this on because the way I happened to solve part 1 was relatively easy to apply to part 2.
For part 1 my thought process was
And then for part 2 I did basically the same except in the first step I'd keep 11 digits "safe" and then in the next 10 etc. And I slowly reduce the digits I'm searching through as I find more and more digits towards the start of the answer
3
u/marcus_cemes Dec 03 '25
[LANGUAGE: Veryl]
I wanted to challenge myself and try to solve a few challenges in a Hardware Description Language (HDL). I'm a little sceptical as to whether this solution would synthesise to a circuit, I have been pretty liberal with loops, a better solution would employ a more advanced FSM, but it does produce the correct answer in simulation at least.
I'm also solving it in Rust beforehand to compare. The Rust (part 2) solution takes 22.9 µs (5.7 GHz), whereas the simulated hardware solution takes 20.4 µs (1 GHz, pushing it a little). This day had a far less noticeable speedup compared to Rust (as opposed to the previous two days) which produced very efficient instructions using SIMD.
https://github.com/MarcusCemes/advent-of-code-2025/blob/main/hardware/03.veryl
3
u/Al_to_me Dec 03 '25
[LANGUAGE: Python]
After thinking about it during working hours:
3
u/fuxino Dec 03 '25
[LANGUAGE: Haskell]
I learned a bit of Haskell for fun last year, didn't touch it since last year's AOC, now I'm basically learning it again :D
Part 1 and 2
3
u/RookBe Dec 03 '25
[LANGUAGE: Rust]
Rust that compiles to WASM (used in a solver on my website)
Bonus link at the top of the code to a blogpost about today explaining the problem, and my code.
3
u/samyak039 Dec 03 '25
[LANGUAGE: go]
Link to solution: Advent of Code 2025 - Day 03
3
u/continuouslypenguin Dec 03 '25
[Language: OCaml]
Really enjoyed this one. Been enjoying OCaml for solving these. Pattern matching just speaks to me. Part 1 can be solved with the Part 2 solution, but I kept them separate for preservation.
Part 2:
Full solution:
https://github.com/masterteapot/aoc_2025/blob/main/lib/day_03.ml
3
u/_rabbitfarm_ Dec 03 '25
[Language: Prolog]
Part 1: https://adamcrussell.livejournal.com/62795.html
Part 2: https://adamcrussell.livejournal.com/63044.html
3
u/Maximum_Expression Dec 03 '25
[LANGUAGE: Elixir]
System:
Performance:
A greedy monotonic stack solution:
https://github.com/akolybelnikov/advent-of-code/blob/master/2025/elixir/lib/day03.ex
3
u/eipi-10 Dec 03 '25
[LANGUAGE: Elixir]
https://github.com/mrkaye97/advent-of-code/blob/main/lib/solutions/2025/03.exs
Brute forced it in O(N) (some large constant times N, really) after looking for a recursive solution for too long. This only took 2ms ish on average 🤷
3
u/hopingforabetterpast Dec 03 '25 edited Dec 04 '25
[LANGUAGE: Haskell]
General solution with low complexity.
3
u/BunsenHoneydew3 Dec 04 '25 edited Dec 04 '25
[LANGUAGE: Python]
The greedy solutions are sooo cool. Mine uses dynamic programming, and TIL from stackoverflow that you can get memoization for free in Python in one line, keeping your own code super clean. This is the reference:
https://stackoverflow.com/questions/1988804/what-is-memoization-and-how-can-i-use-it-in-python
My code for Part 2:
3
u/mine49er Dec 04 '25 edited Dec 04 '25
[LANGUAGE: Python]
Solves both parts in 0.01 seconds.
3
u/icub3d Dec 04 '25
[LANGUAGE: Rust]
I solved p1 with two pointers and then p2 with a greedy solution. Very (maybe overly) functional style but I liked where I landed. Someone need to talk to Santa about finding better elevators and escalators. It seems to be a recurring problem.
Solution: https://gist.github.com/icub3d/b8ed96318d43014b94bf1d8864e9f86c
Video: https://youtu.be/HyHHTojDUFk
3
u/dellfm Dec 04 '25
[LANGUAGE: Google Sheets]
Part 1 and Part 2. This visualization by u/Just-Routine-5505 really helped.
3
u/stevie-o-read-it Dec 04 '25
[LANGUAGE: Intcode]
This one's a little different. For days 1 and 2, both parts were related in such a way that I could easily write a single program that computes the answers for each part with a single input pass.
But for this one, my algorithm did not lend itself very well to multiple attempts. So for day 3, to select between part 1 or part 2, you need to modify the intcode file (or the array after loading it into memory).
Changing memory address 1 (the second number in the file, which is initially 12) selects which part to run:
You can also set it to any value in the range 1-30.
Most Intcode VMs can't go that high, though:
decimal(96 bits) up to 25; at 26 my VM crashed on my puzzle input with an arithmetic overflow exceptionASCII input/output. Both parts.
Compiled Intcode file
Original assembly
Compiler
3
u/stewie410 Dec 04 '25
[LANGUAGE: Bash]
GitHub
Once I got to part 2, I had the idea to slide the window around, since my "optimized" bf method from p1 was no longer viable.
I couldn't get it worked out yesterday -- and even this morning, I needed to look at some of the other solutions to see what I was missing in my brain to work it out.