r/adventofcode • u/daggerdragon • Dec 06 '25
SOLUTION MEGATHREAD -❄️- 2025 Day 6 Solutions -❄️-
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 unlocked!
- 11 DAYS remaining until the submissions deadline on December 17 at 18:00 EST!
Featured Subreddits: All of the food subreddits!
"We elves try to stick to the four main food groups: candy, candy canes, candy corn and syrup."
— Buddy, Elf (2003)
Today, we have a charcuterie board of subreddits for you to choose from! Feel free to add your own cheffy flair, though! Here are some ideas for your inspiration:
- /r/IronChef
- ALLEZ CUISINE!
Today's prompt is totally not bait for our residentIron Coders- /r/GrandmasPantry and /r/TastingHistory
- Deliberately use
depreciateddeprecated functionality of your programming language - Solve today's puzzles using only programming languages that are a minimum of 50 years old
- Hardtack! *clack clack*
- The older the expiration date, the more we'll enjoy it!
- /r/FoodPorn (it's SFW, trust me)
- Bake/cook/decorate something related to Advent of Code
- Show us your 1337 hot cocoa recipe (or other beverage of choice)
- Whatever it is, make it tasty!
- /r/whatismycookiecutter, /r/ShowerOrange, and /r/BreadStapledToTrees
- Show us cookies, citrus, and/or bread in/on/near your Christmas tree/menorah/holiday decorations
- Solve today's puzzle using a food-themed programming language
- Solve today's puzzle using actual food?
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 6: Trash Compactor ---
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?
29
Upvotes
6
u/JustinHuPrime Dec 06 '25
[LANGUAGE: x86_64 assembly]
Part 1 was some fairly fiddly dynamic array allocation, parsing, and accumulating.
Part 2 involved throwing almost everything out and re-doing the parsing and accumulating. This time, I couldn't parse everything into an array first, I had to parse each problem into its own buffer using a double-pointer strategy (one pointer at the characters of the number, one pointer on the line with the operations to index everything) before operating on that buffer. Also, the size of the buffer was dynamic per problem, so involved reallocation. I did have to take advantages of the trailing whitespace that made each line the same length so I could easily move the pointer between lines.
Part 1 and 2 run in 1 millisecond. Part 1 is 9,560 bytes and part 2 is 9,592 bytes as an executable file.
With great irritation, I cannot claim to be using any deprecated features of x86_64 - the instructions I've used today are exceedingly ordinary and common (interestingly, the newest instruction I use is still from 1993 -
syscallis a fairly modern instruction). With even more irritation, I can't even claim to be using a language that's at least 50 years old - the x86 architecture is 47 years old! With yet more irritation, I can't even claim this is a hard language - many esolangs have far fewer features than modern x86_64.6
u/dijotal Dec 06 '25 edited Dec 06 '25
[LANGUAGE: Common Lisp]
So, yes: I picked this hill to die on just to do something clever & lisp-y: If you
you produce a list of valid lisp expressions such as (+ 4 431 623) that can each be directly evaluated (i.e., eval '(+ 4 431 623)) and summed in a big sweep.
Yes, it worked... though It's going to need quite a bit of polish before posting. :-/
[EDIT!]
Ok, less hand-waving, Part 2. [`transpose-strings` is just the usual `apply #'list` stuff, and `read-input-as-strings` is just that, slurping the file into a list of strings -- with the addition of moving the operator row to the top and following it with a line of spaces.]
4
u/Samstrikes Dec 06 '25
[Language: Elixir] Both parts
Been using this year to get more familiar with Elixir and excited to have my largest pipeline yet! Happy with how clean I managed to get this, mostly thanks to discovering
chunk_bywhich I used to find all the blank columns and break up the expressions into chunks.3
u/WilkoTom Dec 06 '25 edited Dec 06 '25
[LANGUAGE: Rust] [Red(dit) One]
Solution
Today,
take_while()is my friend.Oh, did somebody say ALLEZ CUISINE!?
3
u/e_blake Dec 06 '25
[LANGUAGE: m4]
[Red(dit) One]
What a fun day! I solved part 1 with mere
shift($@)recursion (exposing GNU m4 1.4.19's O(n^2) behavior with an execution time of 1.9s, vs. unreleased m4 1.6 with O(n) and just 110ms); with the only reason to use my common.m4 library was to support the mandatory math64.m4 library needed for the 64-bit math on 32-bit m4. That ought to be fun to "boil down" to a golfed solution usingsyscmd(echo $(()))later on. But then I LOVED the surprise ingredient twist in part 2, which had me rethinking how to parse the data. In the end, I came up with what I hope is a "tasteful" solution that solves both parts in 200ms with a single pass over the input file (always nice when solving both parts is 6x faster than my original part 1 speed). My biggest struggles were not on how to transpose data, but on how to generate an eval expression that works correctly even in the presence of an empty string that has to be converted to an identity value of 0 for + or 1 for *, for the portions of my input file that were less than 4 columns wide.As to today's task:
Oh sure. I don't think m4 has any "depreciated" features (they have all aged well with time, none of them have lost value) - but I guess it does have a "deprecated" built-in macro
maketemp. Still, I fail to see how creating an insecurely-named temporary file will help me solve the problem. AND, to "rub salt" in the wound, you picked a cutoff for language 50 years or older, when m4 is only 48. (I don't recall you complaining when I used "m4 stands for MMMM" in Allez Cuisine...) So I'll have to "cook up" something else to impress you.So, for your reading pleasure, here's my recipe on how "stir-fry" a grid of characters into two different arrangements, using only
translit:(And for the spectators in the audience, yes, I really DID name my macro
swizzleprior to ever opening up the megathread and learning about today's tasty challenge; I ought to at least get some credit for choosing an on-theme name beforehand)3
u/dijotal Dec 06 '25 edited Dec 06 '25
[LANGUAGE: Common Lisp]
Edited into last night's post and resubmitted here for a top-level Part 2 summary (https://www.reddit.com/r/adventofcode/s/I5NxULiuwH)..
The only hand-waving here is that function `read-input-as-strings` includes two non-intuitive items:
That moves the operator to the front (with a space before the first digit), creating lisp-y s-exps :-)
4
u/bofstein Dec 06 '25 edited Dec 07 '25
[LANGUAGE: Google Sheets]
Solution (with only Sample sheet visible): https://docs.google.com/spreadsheets/d/1CgvI978Gk_UkaQ3AAvMwI_7XyioEUAo1l03bluu0010/edit?usp=sharing
Part 1 is simple - just SPLIT() them into columns, use the operator to sum or product them with an IF, and then sum it up.
Part 2 is the same thing in the end - just a bunch of steps first to transform the numbers. First I separate out each character individually vertically, concatenate those across into the newly formed numbers, add in some characters to help separate the groupings, do a bunch more of various CONCATENATE/SPLIT/TRANSPOSE to get those numbers back into the format I need for calculation. Which was similar to Part 1 though I had to throw in another TRANSPOSE with a SORT to get the operator to the first column, as otherwise it was in a different column each row of the real input.
There are Notes on cells explaining the logic of the steps. Many of them could be shortened or combined, I was making it up as I went so some columns could have been cleaner.
The rest of my Google Sheets solutions are here: https://github.com/bofstein/advent-of-code-2025/tree/main
2
u/Arayvenn Dec 06 '25
I kinda just forgot .split() existed until seeing some of the solutions here. Definitely would've made part 1 waaaay cleaner. I blame the fact that it's late.
[Language: Python]
Part 1
Part 2
2
u/K722003 Dec 06 '25
[LANGUAGE: Python] 00:03:20 / 00:10:33. Woke up like 2 mins before it started so I went to have food after solving.
Also I hate having to process whitespaces in code (zip_longest made it bearable in p2.... after I remembered it existed :wacky:)
Preprocess func (the day i thought of adding preprocess it took me longer than just doing it manually):
P1: Just compute directly after the preprocessing into column-wise ints
P2: Use zip longest to get digits column wise then join them. Add a marker for an empty col (whitespaces only) to determine where current col ends. Then just do what p1 did
2
u/Last_Fly7536 Dec 06 '25
[Language: Dart]
https://github.com/Noahbanderson/aoc-2025/blob/master/dart/lib/day_6/main.dart
Part 1 was straightforward. The hardest part was parsing, which wasn't that hard.
Part 2, WOW, this was fun!
I made a wrong turn assuming that the column sections were left aligned and had to rework a better solutoin.
The simplest way I found was to transpose the input matrix across the topleft-bottomright diagonal, which made the rest of the solution super simple. Here is what the trasnposition looks like:
2
u/Smylers Dec 06 '25
[LANGUAGE: Vim keystrokes] Load your input, then type the following and the part 1 answer will appear:
The main loop is
@a: Add a new blank line at the top,dwthe first word off each original line and prepend it to the top line. So for the first sum, the top line becomes:Once the final sum has been removed, there'll be a bunch of blank lines at the bottom. The
:%s/\n*\%$removes them (I had to look up\%$for matching at the end of the buffer). That, combined with:set nowrapsearchat the beginning, ensures that the loop will error-out when it attempts another iteration (errors being the only way to exit loops in Vim keystrokes).After the loop, the second
:normon each line deletes the operator from its start and replaces all runs of spaces in that line with the contents of the small-delete register — that is, the just-deleted operator.Finally join all the lines into one big sum and evaluate it, using the
@shelper macro defined it yesterday's part 2.2
u/beretta_vexee Dec 06 '25 edited Dec 06 '25
[LANGUAGE: python] Part 2: I spent more time formatting the data in part two than actually solving the problem.
2
u/Mats56 Dec 06 '25
[Language: Kotlin]
with my transpose-utils and other stuff this became quite straight forward. https://github.com/Matsemann/algorithm-problems/blob/main/adventofcode2024/src/main/kotlin/com/matsemann/adventofcode2024/utils/ListUtils.kt#L40
2
u/markjreed Dec 06 '25
[LANGUAGE: Raku]
Pretty easy today; part 1 was a one-liner. Hyperops FTW!
https://github.com/markjreed/advent-of-code/blob/main/2025/day06/day06.raku
2
u/cafebistro Dec 06 '25
[LANGUAGE: Go]
https://github.com/albertb/advent-of-code/blob/main/2025/06/day06.go
I tried to do part2 as part of the parse, like part1, but gave up once I realized I could simply rotate the input string (so columns become rows). Once rotated, calculating the grand total was trivial.
16
u/jonathan_paulson Dec 06 '25
[Language: Python]. My times: 00:02:14 / 00:11:36. Video of me solving.
Toughest one yet! I think part2 would've been easier without having part 1 first!
It took me a while to settle on using a grid of characters for part 2, but that made things relatively straightforward; a blank column separates different problems, and you can read each number top-to-bottom from a column (or left-to-right from a row for part 1).
16
u/voidhawk42 Dec 06 '25 edited Dec 07 '25
[LANGUAGE: Dyalog APL]
Video walkthrough
16
u/4HbQ Dec 06 '25 edited Dec 06 '25
[LANGUAGE: Python] 9 lines.
Part 1 was pretty simple:
Still, there are a few useful Python tricks hidden in here. First, the built-in zip(*it) can be used to rotate an "array" (a list of lists):
Second, map(f, *it) can take multiple iterables:
Finally, the use of eval(str). We build a string that describes the full calculation and evaluate it to find our answer:
In Part 2, we iterate over the columns of the input to build the string. If we see an operator (instead of a space), we temporarily store it. If we see a number, we concatenate it (and the most recent operator) to the string. An empty column indicates we're done with the problem, so we add a '+' to the string. Not the cleanest code I've ever written, but well:
Update: Here is a more compact solution to compute both parts. I've reduced the problem to an abstract sequence of splitting, zipping, joining. Maybe not everyone's preferred way of solving, but interesting nonetheless:
2
u/Vortetty Dec 07 '25
[language: python]
part 1 was easy, cut out all the whitespace, then part 2 came along and gods help us all part 2 has to be the most cursed python i have ever written
Part 1: Codeberg Link
Part 2: Codeberg Link
i am starting to think committing to onelining every solution was a mistake...
8
u/SheepiCagio Dec 06 '25
[LANGUAGE: Excel]
P1:
P2:
7
u/cinx16 Dec 06 '25
[LANGUAGE: Haskell]
Solution repo
Quite short solution by using "transpose":
6
u/Andreasnl Dec 06 '25
[LANGUAGE: Uiua]
Link
6
u/pred Dec 06 '25
[LANGUAGE: Python] GitHub. Part 2 pretty annoying a priori, but take the punch card representation seriously, and it amounts to transposing the data from part 1;
6
u/evans88 Dec 06 '25
[LANGUAGE: Python]
Part 1 was really easy AND I got to use
functools.reduceandoperator:For part 2 I realized you could transpose the entire input, just resulted in a bit of awkward operator parsing:
5
u/1234abcdcba4321 Dec 06 '25
[LANGUAGE: JavaScript] paste
Nothing special here. I'm just posting this because I'm surprised there's so few solutions posted considering it's already been so long since the problem came out.
I did my first bit of non-coding processing today; I couldn't understand the problem without pasting the input into a text editor without word wrap.
5
u/AlexTelon Dec 06 '25 edited Dec 06 '25
[Language: Python]
Today I was fast on the first part
6 00:02:50 00:28:41!python 10 lines (both parts)
Few tricks for today.
zip(*rows)is a trick to convert form rows to columns or the other way around.eval(op.join(operands))to do the calculationIt was tricky to parse correctly for the second part. I had to use
zip_longestto ensure we got all the full numbers on the last column.Edit:
.replace('*',' ').replace('+',' ')->.replace(op.strip(), ' ')Edit2: python 10 lines (both parts)
In this version the similarities between p1 and p2 are clearer:
Edit3: python 7 lines both parts
My goal here was to make the difference between p1 and p2 super obvious in the code.
Though that is the only part that is more obvious as the rest is very compressed.
5
u/p88h Dec 06 '25
[LANGUAGE: Odin]
Solution: [ GitHub ]
Yay, parsing, my favourite source of errors, managed to get both buffer overruns, bad indexes and off-by-ones today.
5
u/light_switchy Dec 06 '25
[LANGUAGE: Dyalog APL]
Part 1:
Part 2:
5
u/thedrj0nes Dec 06 '25
[LANGUAGE: InterSystems ObjectScript / MUMPS]
An easy puzzle to lull me into the weekend, which makes me worry what will come tomorrow, but we will see.
Day 6
I do like the simple and clean logic of Reverse Polish Notation, this is clearly the inspiration here.
If I thought more about it at first, I could have written something for part one that could have been reused more for part 2 just changing the read order, but not to worry.
The MUMPS eXecute command is a really good one for getting away with all kinds of lazy naughtyness. If you ever execute something the user inputs, be very careful. You can chain all sorts in there and it won't validate it.
$ZSTRIP is a InterSystems specific function I think, it can remove occurrences of a pattern, in this code, "<=>W" mean trim leading, repeating and trailing white space from the string.
All done in <5ms (part 1) and <3ms (part 2).
5
u/JWinslow23 Dec 06 '25
[LANGUAGE: Python]
Solution writeup
Code (GitHub)
Today, I found that
itertools.groupbyworks very well for the main parsing problem of Part 2: grouping the columns using all-space columns as separators. I love hidden standard-library gems like that.(Final time: 25:15. Most of that time was spent trying to find a good way to split by the all-space columns for Part 2. My original solution was something with
itertools.pairwiseand slicing withNone; I'm glad I found a better way!)5
u/dzecniv Dec 06 '25
[LANGUAGE: Common Lisp]
I rotated the input (as a string) for part 2, not in the direction planned though :p but it worked (and fast).
part1:
src part 2
4
u/python-b5 Dec 06 '25
[LANGUAGE: Lily]
Well, I figured we'd get to the parsing puzzle eventually. I got stuck for a while after I realized the columns weren't all the same size in the real input. I'm not especially happy with my parsing logic, but it appears to do the job, and at this point I think I'm better off not messing with it any further.
On a side note, does anyone know what all that "right-to-left" talk was for? Addition and multiplication are commutative, so it doesn't matter what direction you do the puzzle in, right...? I just did it all from left-to-right since that was easier. I just wondered if I was missing something.
https://github.com/python-b5/advent-of-code-2025/blob/main/day_06.lily
4
u/sauntcartas Dec 06 '25
[Language: Raku]
Part 1:
Part 2:
4
u/Kullu00 Dec 06 '25
[LANGUAGE: Dart]
It took me a number of false starts and bad decision before solving part 2 and I'm still not sure I'm happy with it.
Rather than transposing first, split each problem into it's own tiny 4x2, 4x3 or 4x4 grid and solve both parts in parallel. This ended up working out really neatly. The biggest pain was making sure whitespace was maintained at all times.
2025 Day 6
4
u/JarroVGIT Dec 06 '25
[LANGUAGE: Rust]
Github
I feel dirty. I mean, I love iterator adapters in Rust and I try to use them as much as possible, especially in these kind of puzzles. But once you run
rustfmt, you are left with lines and lines of adapters.For part 2 today, I couldn't find a way to do this without
Stringallocation. I had some code that that basically did* 10.pow(exp)to build up the numbers, but they were not aligned, meaning that a single-digit-column could have the digit in the first or last row. Curious how others solved this, I don't like my solution at all but it is quite fast (faster than I expected tbh).4
u/CrumblingYourSoul Dec 06 '25 edited Dec 06 '25
[LANGUAGE: Zig]
Arrays + SIMD
For part 1 parsed each line into seperate arrays based on the last line and then used SIMD to sum and multiply them in one go.
For Part 2 i did a similar scheme where I setup arrays for holding numbers that needed to be multiplied and added. Parsed it 1 line at a time and collected the numbers within these arrays. Finally the same SIMDized step was used to find the final result.
Part 1: ~47ms cold and ~15us @ 20,000 iterations
Part2: ~58ms cold and ~17us @ 20,000 iterations
Code
4
u/NukeyFox Dec 06 '25
[Language: Haskell]
Both parts solved in 44 lines: Github
Basically the idea is that the inputs is parsed in two different ways, before being passed to a solver function.
4
u/Zorr0_ Dec 06 '25
[Language: Kotlin]
String manipulation for the win!
Using List.split() and List<List>.columns() function made part 2 a lot less hustle
GitHub
4
u/azzal07 Dec 06 '25
[LANGUAGE: awk] Bit tedious parsing and transpositions for the second part, but turned out quite nice.
4
u/hugh_tc Dec 06 '25
[LANGUAGE: Python 3]
Spent most of Part 1 thinking to myself: "This is so suspicious, I'm going to have to re-do this input parsing for sure."
https://github.com/hughcoleman/advent-of-code/blob/main/2025/06.py
4
u/systemnate Dec 06 '25
[Language: Ruby]
Finished part 1 very quickly, but failed to read the "right-aligned" part and went down an approach where I was trying to add the ones, then tens, then hundreds, etc. of the number.
Fun fact: the problem mentions a "magnetically sealed garbage smasher", like in Star Wars: Episode IV. The solution to the sample input for part 2 is 3263827, which is the number of the trash compactor in Star Wars.
4
u/tymscar Dec 06 '25
[LANGUAGE: Gleam]
Yet another fun puzzle!
For part 1, transpose came in clutch. It did exactly what was needed, and then I just ran a case statement over what to do: sum them or multiply them. Finished it in a couple of minutes.
Part 2 took me ages, not because it was difficult, but because of loads of tiny issues. The biggest one you should be careful about is that IntelliJ removes trailing white spaces from text files. I have tried looking in settings to disable that, but I can't for the life of me find where. I ended up editing my inputs only with Vim. To solve part 2, I basically created a function that, based on the math operation at the bottom, found the strides needed. Then I chunked up the inputs based on those strides. At the end, a simple transpose again saved the day, and all I needed to do was to parse those as big ints (to be sure they don't overflow). Now, the bigi library in Gleam, for some reason, gives back an error if you try to parse something that also contains white spaces like " 1". That was a bit annoying. Most other languages I know don't do that.
The only other thing I found weird about Gleam is how you can't have multiple statements on the same `case` line. So, you're forced to copy and paste the expression for each statement you think fits.
Part1 and Part2
4
u/Jadarma Dec 06 '25
[LANGUAGE: Kotlin]
A nice puzzle this time focusing on your ability to parse complex inputs instead of solving difficult algorithms. Then again, I don't want to help anyone do their homework anytime soon!
Part 1: I got to enjoy making an overly-complicated type definition to encapsulate the math problem, because I ended up scrapping the input parsing for part two.
Part 2: Be careful with removing trailing spaces, I do this as a "best practice" so I had to pad them back manually. To make something that is reusable for both parts, I first iterated through all the columns, made a note at what indexes all the rows are blank, and created slices that would tell me from where to where a problem resides. Then, to parse the problems, I simply took every input line substring at that slice, kept the last for the operation, and if part two, also translate the strings column-wise before parsing them in actual numbers.
AocKt Y2025D06
4
u/Working_Way Dec 06 '25
[LANGUAGE: Common Lisp]
Approach: rotate the whole input, then handle as if it were given as lisp data.
Part 1 is commented for everyone interested, what is done.
Part 2 does the essentially the same, but rotates the input before parsing it. So some conversion string -> char and back is needed.
4
u/LiquidProgrammer Dec 06 '25
[LANGUAGE: Javascript]
Github. Does both part 1 and 2
4
u/cetttbycettt Dec 06 '25
[Language: R]
4
u/mcars75 Dec 06 '25
[LANGUAGE: Python]
1
u/mestar12345 Dec 06 '25 edited Dec 06 '25
[Language: F#]
1
u/LeackyBee Dec 06 '25 edited Dec 07 '25
[Language: Python]
This tripped me up a lot, and there's absolutely ways to make it more efficient/cleaner
https://github.com/LeackyBee/coding_challenges/blob/main/AdventOfCode/2025/6)%20Trash%20Compactor.py
1
u/Zooty6 Dec 06 '25
[LANGUAGE: Java]
Parsing the input for part2 was hell, everything else is straight forward. Also I failed to copy-paste the example and left a white space from the end of the file, that caused me some headache.
Also for a while I called my variable
stupidHentaiOperationsto express my frustration against squid math.I tried to follow oop principles as much as possible, even managed to use inheritance between the two parts, so that's neat.
[github link for my solution]
1
u/NikolaIcic Dec 06 '25
[LANGUAGE: C#]
Day 6
https://github.com/NikolaIcic/AoC/blob/master/2025/Advent2025/Day6.cs
1
u/FizzyElt Dec 06 '25
[LANGUAGE: OCaml]
flip matrix function will help you
part1
https://github.com/FizzyElt/ocaml_aoc_2025/blob/main/bin/day6/q1.ml
part2
https://github.com/FizzyElt/ocaml_aoc_2025/blob/main/bin/day6/q2.ml
1
u/babyccino Dec 06 '25 edited Dec 06 '25
[language: rust]
https://github.com/babyccino/advent-2024/blob/main/2025/src/six_clean.rs
1
u/MarcusBotto Dec 07 '25 edited Dec 07 '25
[Language: Vim?]
I solved it using vim motions and macros, though I'm using neovim.
https://github.com/MarcusBoay/aoc-a2025/blob/main/aoc2025/6.nvim
Simply yank the commands seen into the registers. (You might need to :let `@q` = "..." for it to work) The registers that don't need to be yanked before hand are `a`, `h`, `y`. ` X` is necessary to append to the end of the operator line to make the last problem be solvable. The line numbers are also strict since there's a lot of going to specific line numbers. In order to start solving once you've all the registers saved, simply go to the top of the file and play back register m, like `40@m`.
Here's my post of it happening: https://www.reddit.com/r/adventofcode/comments/1pg77kf/2025_day_6_part_2_vim_solving_with_macros_and_vim/
1
u/marconisdev Dec 07 '25
[LANGUAGE: Elixir]
I'm learning Elixir with AoC this year, please give me feedback on my code as it helps me learn :)
https://github.com/david-marconis/aoc/blob/main/y25/src/day6.ex
This was a bit of a doozy, but I learned how to transpose a list! I white space padded the lines for part 2 and did a double transpose, lol.
1
u/ConstantGazelle Dec 09 '25
[LANGUAGE: Typescript]
Solution.
3
u/davidsharick Dec 06 '25
[LANGUAGE: Python]
Code
The logic was pretty easy for this problem, but refactoring my input parsing when I realized that using
.split()was destroying whitespace information I needed was not.3
u/seligman99 Dec 06 '25
[LANGUAGE: Python]
github
Cute puzzle. Kinda broke me pivoting the grid, but I got there, so I'm happy.
3
u/YenyaKas Dec 06 '25 edited Dec 06 '25
[LANGUAGE: Perl]
Today nothing especially Perl-ish, just one
evalin Part 2. The unusual property of today's tasks was that I had to actually modify my parsing code between parts 1 and 2. In Part 1, I used the 2D map with non-whitespace strings:and in Part 2, the standard character-based one:
Anyway, my complete solutions are here: Part 1, Part 2
3
u/Boojum Dec 06 '25
[LANGUAGE: Python] 00:04:19 / 00:11:31
(I beat /u/jonathan_paulson to the second star?! Crazy!)
Part 1:
Part 2:
Anyway, for Part 2, I used the
zip( *iter )trick to pivot the input into a list of columns. Then I treated it like a state machine as I iterated the columns. If there's a'*'at the end , set the operator to multiplication and initialize the accumulator to the identity element one. Or if there's a'+'set the operator to summation and initialize the accumulator to the identity element zero. If I get a column of all the same thing, it's gotta be all whitespace (including the newline at the end), so were done with that problem and can add the accumulated result to the grand total. And if it's not all whitespace, we can use the operator to fold the number into the accumulator.3
u/syh7 Dec 06 '25 edited Dec 06 '25
[LANGUAGE: Kotlin]
My editor did not allow the spaces to stay at the end of the input, so I had to add padding to each line. Afterwards, it is a reverse iteration and keeping a list of numbers read so far, until we find a new operator.
3
u/morgoth1145 Dec 06 '25 edited Dec 06 '25
[LANGUAGE: Python] code video Times: 00:02:17 / 00:10:09
I don't have much to say about part 1, other than it led me down a path that actually caused me to dig my own grave a bit in part 2!
The part 2 twist was definitely unexpected, I've never had to parse a text table where the whitespace matters before. After part 1 I was fixated on using my
lib.gridlibrary (which made the part 1 parsing super easy) which honestly made it more difficult than it needed to be. As I was cleaning up my commit message I already realized an easier way to do the parsing for part 2, I'm going to get on that right after posting this.As for my live approach, initially I re-used the grid from part 1 and modified how the numbers were parsed from the column to take the digits out, but this is no good when whitespace in the column was not preserved! Normally splitting on whitespace is exactly what you want in grid-based problems so trying to preserve whitespace was interesting. If you look at my part 2 code you'll see that preserving whitespace was...special. It took me just about 5 minutes to get that part right!
Now off to write a much simpler solution... (Edit: Actually now that I'm writing it I'm realizing it's a little more complicated than I thought. Plus I probably could have leveraged my
lib.gridlibrary in another way to make part 2 easier!)Edit: Cleaned up solution making use of my
lib.gridtranspose functionality. That drastically simplifies the number parsing in part 2 by letting me rely on whitespace again!Edit 2: Simplified parsing for part 2 using comprehensions. Not sure why I didn't do that before!
3
u/SuperSmurfen Dec 06 '25 edited Dec 07 '25
[LANGUAGE: Rust]
Times:
00:05:41 00:17:56Link to full solution
Hard parsing problem today! For part two, I iterated column by column. If the column is empty, the current problem has ended so I push a new vector. Otherwise, add the column to the current problem:
Then you just compute the product or sum for each problem:
3
u/mstksg Dec 06 '25
[LANGUAGE: Haskell]
https://github.com/mstksg/advent-of-code/wiki/Reflections-2025#day-6
Our trusty friend
transposecomes in handy here!For part 1, we parse the grid and then transpose and reverse each line, matching on the
headto get the operation we care about:And for part 2, we actually can transpose the entire long strings to get "columns". Splitting on blank columns, we see that they are pretty straightforward to process:
We just need to grab the
+and then add the rest. Lots of ways to do this, I ended up usinginit(gets all but the last item) andlastfor my solve:3
u/alexbaguette1 Dec 06 '25
[Language: Python]
Numpy for 1 operation lol
3
u/ricbit Dec 06 '25
[LANGUAGE: Python]
My first wrong answer of the year, I didn't notice the input had 4 rows of numbers instead of 3 like the example!
https://github.com/ricbit/advent-of-code/blob/main/2025/adv06-r.py
3
u/maneatingape Dec 06 '25 edited Dec 06 '25
[LANGUAGE: Rust]
Solution
Today's problem was hilarious fun! 20µs total.
For part one there's no need to collect the numbers into avecthen transpose them. Instead we can build avecofIteratorfor each row, then advance them all simultaneously.EDIT: Changed part one to also use the 2D grid which was faster.
For part two briefly thought about using logarithms to find the highest power of ten, but then decided to use a 2D grid to parse columns of digits which was surprisingly quick.
3
u/cay_horstmann Dec 06 '25
[Language: Java] https://github.com/cayhorstmann/adventofcode2025/blob/main/Day6.java
What a mess! In hindsight, I should have transposed the input and then parsed it.
3
u/Busy-Championship891 Dec 06 '25
[LANGUAGE: Python]
(Part-1)
Its relatively easy to do part-1 by just following the instructions. Split lines into numbers and sum column-wise after getting result using the operator for that column.
(Part-2)
Part-2 seemed tricky but the trick I used is to process the input and find any columns with any-digits in that column. If there are any digits in the column, the empty spaces are replaced with '0' which helps in splitting numbers later.
Then simply processing numbers column-wise and replacing '0' back with empty character. Although I think there might be better ways to do it!
Link: https://github.com/D3STNY27/advent-of-code-2025/tree/master/day-6
3
u/FransFaase Dec 06 '25
[Language: C]
Not very difficult with respect to the logic, but I struggled a lot with all the small details and also a warning that I missed, which was actually an error, making me decide to let the C compiler report all warnings and consider them as errors.
See https://github.com/FransFaase/AdventOfCode2025/blob/main/Day06.md for a mark down file, with all my attempts. I process this mark down file with a program I wrote myself that parses all the C fragments, takes the last definition if it occurs more than once, and generates a C file with all the elements in the correct order to be compiled. (It does generate forward definitions for all function, such that the order of the functions does not matter.) The generated C file can be found at: https://github.com/FransFaase/AdventOfCode2025/blob/main/day06.c
3
u/Salusa Dec 06 '25 edited Dec 06 '25
[Language: MUMPS]
Part two took me a ton of time because I forgot to reset a variable at the top of an inner loop. Other than that, I'm pretty happy with my solution. I've added in logic to measure how long my code takes to run because I've always been a bit of a micro-optimizer.
Part 1:
27.7 ms (26.6 ms was parsing)(Rewrote parser because it was too slow. Now only 13.8 ms to parse. Math remains about 1.1 ms)
Part 2: 16.4 ms (14.2 ms was parsing)
I find it interesting that my part two parsing logic was so much slower than my part 1. I suspect it was because I was continually (implicitly) splitting the string on spaces while for part 2 I simply indexed over the characters directly.
Day 6
3
u/Sad_Improvement_2619 Dec 06 '25
[Language: LuaJIT]
Took a bit longer than I had hoped to conceptualize how to solve part 2. At first I was just going to take part 1 and do some division by 10 to rotate the numbers, but luckily I noticed that the alignment changes before I actually started doing it.
Whenever I see other people's solutions, they are always much shorter than mine. Idk if that's cause Lua lacks some of these QoL features, or if I just suck. Either way, 6-7 millis for both parts is decent enough for me for my little scripting language (could probably optimize but oh well).
Glad programming algos isn't my day job
https://pastebin.com/uSfX96bt
3
u/irelai Dec 06 '25
[Language: OCaml]
First part was pretty quick, parse the numbers, then transpose to get the problems grouped.
For part 2 I ended up transposing the whole problem, then iterating through the whole thing setting the
operatorwhen a line ended with*or+and adding to the tally whenever an empty line occured. code3
u/Dense-Virus-1692 Dec 06 '25
[LANGUAGE: Gleam]
I'm so glad I found the list.transpose function a little while ago...
paste
3
u/atweddle Dec 06 '25
[LANGUAGE: Rust]
GitHub part 1: 35 µs
GitHub part 2: 20 µs
For part 2, the instruction to go from right to left can be ignored, since addition and multiplication are commutative. Going from left to right instead, we know what the operator is before we start operating on each batch of numbers. Then it's just a fold operation, keeping track of the total, partial batch total and the batch operator in the accumulator.
Performance measured on a MacBook Pro M4 Pro, excluding file I/O.
The lib.rs file contains the shared code to load a file and time many runs.
3
u/xelf Dec 06 '25 edited Dec 06 '25
[LANGUAGE: Python, but if PEP8 was on vacation]
first we read the nums and ops in,
we then rotate the nums, and group them
lastly we sum the prod or sum of each row, using zip to get the op
edit
Originally wrote p1 using pandas, here I've cleaned it up to solve along with p2:
3
u/Daniikk1012 Dec 06 '25
[LANGUAGE: BQN]
Used BQNcrate this time for useful string splitting idioms. I should use it more
3
u/michelkraemer Dec 06 '25
[LANGUAGE: Rust]
GitHub
I solved the first part by splitting all lines by whitespace into Vecs and parsing all entries to integers except for those in the last line. Depending on the operator in the last line, I then simply summed up or multiplied all entries in each column and added the result to the total.
For part 2, I considered the input as a grid. I iterate through the grid column by column. Whenever I find an ASCII digit, I add it to the current number. When I find an operator (
+or*), I set it as the current operator. After each column, I check if the column was completely empty. If not, I update the current sum or product based on the current operator and the number just parsed. Otherwise, I update the current running total. After the last column, the current sum or product also needs the be added to the total.3
u/POGtastic Dec 06 '25
[Language: OCaml]
Code
dawwwwgggg there are too many transposes going on
My code is kinda crap and could easily be refactored with Part 2's parsing scheme, but it's not too big of a deal.
Part 1 gets parsed with plain ol' parser combinators. It's just a
sep_by (many1 space) digits, followed by a transpose, followed by mapping a fold.For Part 2, I used set intersections to find the column spaces and wrote a function to "divvy" a list of elements into chunks, which preserved the whitespace. I then did the transposes of those lists of strings and constructed numbers from the result of that.
OCaml is way, way more annoying about its stdlib with these operations than F#. A bunch of things only work with
Seq. A bunch of things only work withList. So it's extremely common to have to dobecause
Stringonly converts to and fromSeq, notList. Contrast toF#, which uses interfaces and is happy to treatListas an implementor ofSeq(since in that language,Seqoperations work on anyIEnumerable). Grumble grumble grumble grumble grumble3
u/lunar_mycroft Dec 06 '25 edited Dec 06 '25
[LANGUAGE: Rust]
Again a quick and simple part 1, but parsing part 2 was annoying.
full code. Part 1 is fairly straight forward: split on lines, validate that the input is the right shape, then take the transpose and parse the numbers using
<u64 as FromStr>::from_str. Part 2 is a mess: I start by identifying the operators and the borders of the columns, then use those bounds to split the input into aVec<Vec<str>>, where thestrs are the (padded) numbers as they appear in the input. From there it's "just" a matter of getting the columns the same way I did in part 1, taking the transpose of the columns themselves, then adding and multiplying the digits into the final numbers. Both parts parse in ~180µs and the actual computation occurs in ~25µs.Modified
Puzzlestruct to contain a parsed version of the last row, and all other rows verbatim. For part 1, stole another one of /u/maneatingape's ideas and removed the nestedcollect(although I see they've switched to another solution, and I'll probably do the same tomorrow). For part 2, switched to parsing the numbers into myGridstruct and iterating over the columns (also shared with /u/maneatingape's solution, although I had planned to do that before checking theirs). On my machine (pre-)parsing now takes ~10µs, part 1 takes ~50µs, and part 2 ~100µs.3
u/sim642 Dec 06 '25
[LANGUAGE: Scala]
On GitHub.
In part 1 I split the lines by whitespace and transposed the list of lines of columns to get the input corresponding to each problem.
In part 2 I transposed first and then split (at empty columns) to keep the column alignment and parse the input from that.
3
u/woond3r Dec 06 '25
[Language: OCaml]
https://github.com/KacperKopiec/advent-of-code/blob/main/2025/day6/part2.ml
Boring day, the only problem i had was that OCaml doesn't have builit zip function which I had to implement myself and ofc no String.to_list function for some reason, so had to String.to_seq List.from_seq....
3
u/welguisz Dec 06 '25
[Language: JAVA]
Code: https://github.com/welguisz/advent-of-code/blob/main/src/com/dwelguisz/year2025/TrashCompactor.java
Part 1: So easy
Part 2: Became a parser nightmare. Finally got everything to align and finding these small bugs here and there.
Will definitely need to work on the code and clean it up.
3
u/euporphium Dec 06 '25
[LANGUAGE: Python]
Part 1
Part 2
3
u/sbt4 Dec 06 '25
[LANGUAGE: Clojure]
It's not the prettiest, but it works.
code
3
u/NerdyPepper Dec 06 '25
[LANGUAGE: haskell]
solved & explained with literate haskell!
- Day 6 in the book of solves: https://aoc.oppi.li/2.4-day-6.html#day-6
- Source: https://tangled.org/oppi.li/aoc/blob/main/src/2025/06.lhs
3
u/PangolinNo7928 Dec 06 '25
[LANGUAGE: Javascript]
Solution
Realised far far too late that the operators lined up with start of each column - then it was just regex to get the match indices to determine column start/end, slicing to get the numbers (i leave each row as a giant string to preserve the spaces for alignment) and everyone's favourite
eval😂Both parts in same pass, runs in ~7ms incl parsing
3
u/KindComrade Dec 06 '25 edited Dec 06 '25
[LANGUAGE: C#]
I initially chose the wrong direction and tried to work with the numeric representation of the number, but it looks like that approach is very hard to implement here. In the end, I rewrote everything to use strings. I'll try to improve the code a bit later today.
UPD:
Rewrote both parts. Now parsing is done in a single pass in both parts.
Time:
Code - github
3
u/gyorokpeter Dec 06 '25
[Language: q]
3
u/MrPulifrici Dec 06 '25 edited Dec 06 '25
[Language: Javascript]
A bit harder than the previous ones because I thought the indentation doesn't matter, but on the second part it did so I had to rewrite everything:
3
u/steve_ko Dec 06 '25
[Language: Swift]
https://gist.github.com/steveko/0b6f29ab6a9f991b36fdbd86caec75d8
3
u/Pyr0Byt3 Dec 06 '25
[LANGUAGE: Go] [LANGUAGE: Golang]
https://github.com/mnml/aoc/blob/main/2025/06/1.go
I don't particularly enjoy these tricky parsing problems, so I probably won't be cleaning this up any further.
3
u/carllom Dec 06 '25
[LANGUAGE: python]
I always feel a bit dirty when doing eval (could have used prod/sum instead) but it was too good to pass on.
3
u/sheshanaag Dec 06 '25
[LANGUAGE: Haskell]
3
u/kwenti Dec 06 '25 edited Dec 06 '25
[Language: Python]
Solution (19 lines)
My allies today were:
operatormodule providing functional equivalents of the language's built-in operators:*operator that can be combined withzipto easily express transposition, e.g.:3
u/UseUnlucky3830 Dec 06 '25
[LANGUAGE: Julia]
Relatively straightforward, parsing the input in two different ways was the main bottleneck. For part 1 I
split()the numbers into a vector of vectors, then iterate over the inner vectors first. For part 2 I convert the input into a rawMatrixof characters and go column-by-column, incrementing the operation whenever I encounter a blank column.In my first attempt I used
parse(Int, ...)for part 2 as well, then optimized the code a bit by parsing the numbers manually.GitHub
3
u/SodaDrunkenski Dec 06 '25
[LANGUAGE: Python]
Solution
Pretty simple one I think. zip() doing a lot of work here.
3
u/xiety666 Dec 06 '25
[LANGUAGE: C#]
https://github.com/xiety/AdventOfCode/blob/main/2025/0/Problem06/Problem06.cs
3
u/Prior-Advice-5207 Dec 06 '25 edited Dec 06 '25
[LANGUAGE: Ruby]
Today I felt like revisiting a language I loved like a decade ago…
Array#transposewas very handy for part 2!https://github.com/diktomat/AdventOfCode/blob/main/2025/d06/d06.rb
3
u/xHyroM Dec 06 '25
[LANGUAGE: Python]
https://github.com/xhyrom/aoc/blob/main/2025/06/solution.py
3
u/raevnos Dec 06 '25
[LANGUAGE: Racket]
paste
The trick for part 2 was to use the last line of the input, with the operations, as a guide for how to split up the rest into columns of numbers and spaces.
3
u/Loop_Dreams Dec 06 '25
[LANGUAGE: clojure]
Parts 1 & 2 https://git.sr.ht/~loopdreams/aoc-clj-2025/tree/main/item/src/aoc_clj_2025/day06.clj
3
u/extractedtarball Dec 06 '25
[Language: Clojure]
part1 was really concise, but part2 made it a bit larger
3
u/DeadlyRedCube Dec 06 '25 edited Dec 06 '25
[LANGUAGE: C++]
Parts 1 & 2 on Github
The code for this one got complex because after I solved it using normal string parsing routines, I went back to see how fast I could get it to run and basically ended up parsing things straight out of the "grid".
So ultimately for part 1:
0and multiply columns with1)For each row above that:
And then, part 2 (completely ignoring that the description insists it should be done right to left because order of addition and subtraction doesn't matter):
0if the first operator is+, or at1if it's*For each column of input:
If there's no value
Else
Logic isn't too complex, I think, but the code is all character-by-character parsing.
...but it runs in 0.68ms so that's a win to me!
3
u/anaseto Dec 06 '25
[LANGUAGE: Goal]
Mostly a parsing problem today, but still fun enough.
3
u/No_Mobile_8915 Dec 06 '25
[LANGUAGE: Python]
Part 1:
Part 2:
3
u/icepopo Dec 06 '25
[LANGUAGE: Clojure]
Code
P1 parse the numbers and transpose to get the groups
P2 do that in reverse order, first transpose to get the numbers from columns, then parse
3
u/trevdak2 Dec 06 '25 edited Dec 06 '25
[Language: JavaScript]
Golf
Part 1, 114 Bytes:
Part 2, 182 bytes. I think this could be improved with a clever string replace and eval
3
u/NeilNjae Dec 06 '25
[LANGUAGE: Haskell]
Par1 1 was parsing.
Part 2 was hacking away at list manipulations until I got something that looked right.
Full writeup on my blog, and code on Codeberg.
3
u/_tfa Dec 06 '25
[LANGUAGE: Ruby]
Part 1
Part 2
3
u/spyr01d Dec 06 '25 edited Dec 06 '25
[Language: Kotlin]
3
u/ziadam Dec 06 '25
[LANGUAGE: Google Sheets]
Part 1 & 2 (expects input in A1)
Repo
3
u/vanZuider Dec 06 '25
[LANGUAGE: Haskell]
Both parts
Fortunately for part 2, the function that transposes a list of lists of words can just as well transpose a list of lists of characters. It was a bit of a headache until every function spit out the correct depth of recursions of lists (of lists of list...), but I'm pleased with the result.
Code snippet:
A simple, elegant function that reads a string and returns a function which coalesces an entire list into a single value. I'm trying to imagine what a horrible mess with function pointers the type signature of this would have been in C.
3
u/WolfRushHour Dec 06 '25
[LANGUAGE: Julia]
This was a fun one.
3
u/siddfinch Dec 06 '25
[LANGUAGE: Pascal]
Submitted for your approval: A programmer who thought they understood reading comprehension...
Part 1: "Okay, read the numbers top-to-bottom, this is straightforward."
Part 2: "lol no, read them right-to-left, each column is ONE number, by the way"*
*It only took me 20 minutes of reading to get that
Me: furiously refactors while questioning every assumption I've ever made
The cephalopods read right-to-left. Of course they do. In hindsight, I should have known, tentacles probably don't do left-to-right.
Implemented in Pascal because when you're trapped in a trash compactor, helping with math homework, you use a language from 1970. The comments-to-code ratio is approximately 3:1. The existential crisis-to-enlightenment ratio is also 3:1.
Codeberg
3
u/greycat70 Dec 06 '25
[LANGUAGE: Tcl]
Part 1, part 2.
As I explain in the comments in part 2, I did the parsing by using the column numbers of the operators in the final row to determine where the operands begin and end for each sub-problem. The operators are always directly under the first column of operands, and the final column of operands is 2 less than the next operator's column. (I added a fencepost for the final one to make it easier.)
3
u/eipi-10 Dec 06 '25
[LANGUAGE: Elixir]
Part I was trivial, but Part II was a pain - I'm sure there's a nicer way, but I iterated over the grid to find the indices of the column breaks, adding padding to each column since my editor removed it, and the transposed all the rows into numbers using a placeholder `-` to not lose any info 🤮
Runs in ~200ms
https://github.com/mrkaye97/advent-of-code/blob/main/lib/solutions/2025/06.exs
3
u/ywgdana Dec 06 '25
[LANGUAGE: C]
Part 1 was just tedious parsing (let me be clear that was a C problem, not a problem with the puzzle!!). Like 60 lines of my code could have be replaced by 1 line of C#...
Part 2 was quite fun! I thought my routine for finding the columnar numbers then calling the operation was a bit clever. I started from the right side, walked down the columns building/stashing the numbers and when I hit an operation, did the calculation, reset my number list and kept moving toward the left. Certainly fun to code anyhow.
github!
3
u/scarter626 Dec 06 '25
[LANGUAGE: Rust]
https://github.com/stevenwcarter/aoc-2025/blob/main/src/bin/06.rs
Times (averaged over 10k samples):
Part 1: 9.9µs
Part 2: 8.6µs
Took a bit of refining to minimize allocations.
I used a pretty naive split_whitespace on part 1 originally, but adjusted that after part 2 ran faster when I explicitly identified the start/end ranges for each section so I could do the column-specific checks. Now both parts operate pretty similarly, I just change how I iterate over the data but pretty much everything else is the same between both parts.
I'm pretty happy that so far, all my solutions complete in under 1ms combined (averaged from benchmark runs).
3
u/Ok-Bus4754 Dec 06 '25
[Language: Rust + python]
ported my earlier python solution
trick for part is to transpose the input then it is straight forward like part 1
took me a while to optimize because even rust release was slower than python because of string creation now fixed
same typical trend, rust debug slightly slower, rust release really fast
https://github.com/Fadi88/AoC/tree/master/2025/days/day06
3
u/Nemin32 Dec 06 '25
[LANGUAGE: Common Lisp]
Codeberg
Part 2 was a bit rough. Nothing I couldn't eventually tackle, but man, after how much of a breeze the first half was, I did not expect this.
3
u/clouddjr Dec 06 '25
[LANGUAGE: Kotlin]
GitHub
3
u/molochwalk Dec 06 '25
[Language: Factor]
Advent of parsing is back!. Did part 1 with the EBNF parser.
Part 2, wasn't so bad with just the repl and regular sequence functions.
3
u/wc_nomad Dec 06 '25
[LANGUAGE: Rust]
I went back and re did part 2, Originally i was trying to reuse a struct I had created for part 1, but the parsing was sloppy and it was just a mess.
I broke each line into a vec of chars, reversed each one, then set a global index, for each vec, building the number that was found from the char index of each line and storing it in a buffer. then having a special case for the last line, if a '+' or '*' was found, summing or finding the product of the buffer and then clearing the buffer.
I seem to have fallen into a habit of attempting to do the problems in the middle of the night when they become available, and sloppily throwing code together to get a working solution. Going to bed, and making the solution pretty once I have some rest in me.
https://github.com/imcnaugh/AdventOfCode/blob/main/2025/day_6/src/main.rs
2
u/silenceofnight Dec 06 '25
[LANGUAGE: rust]
An ugly rust solution: https://github.com/jmikkola/AoC2025/blob/master/day6/day6.rs
Part 2 starts by transposing the grid to make it easier to think about
2
u/Queasy_Two_2295 Dec 06 '25 edited Dec 06 '25
[Language: Python]
2
u/abnew123 Dec 06 '25
[Language: Java]
Lots of .trim() initially used to deal with integer parsing (to be totally honest, no idea if it's necessary or if Integer.parseInt in java is smart enough to ignore whitespace). Also definitely hardcoded the fact there were four lines in the input, going to refactor that out.
Solution
Live Solve
2
u/Tight_Musician3943 Dec 06 '25
[LANGUAGE: Python]
Part 1, Part 2
cols = list(zip(*rows))doing the heavy lifting.2
u/kequals Dec 06 '25
[Language: Python]
Solution
If you transpose the input first it becomes much more manageable.
2
u/ironbloodnet Dec 06 '25
[LANGUAGE: JavaScript]
Parsed part 2 in a naive way
2
u/agorism1337 Dec 06 '25
[LANGUAGE: AWK]
https://github.com/zack-bitcoin/adventofcode/tree/master/2025/day_06
2
u/melochupan Dec 06 '25 edited Dec 06 '25
[LANGUAGE: Crystal]
In part 2, after all that reversing and transposing, we get a sequence like
I ended up ignoring the empty strings and using a stack to accumulate values until I see a string with
+or*at the end and then adding or multiplying the stack contents. I now see I could have split the sequence on the empty strings and process whole chunks at a time, without needing the stack. Well, hindsight is 20/20...The code:
2
u/WAXT0N Dec 06 '25
[Language: Python]
Fairly proud of my solution to part 2, part 1 is nothing special
2
u/AtomPhys Dec 06 '25
[LANGUAGE: q]
This was a relatively simple one with q, relying on the "value" keyword, which can take a string input and evaluate it. So the task becomes taking the input, and reformulating it to produce something like
Using "value" on this, we return the product of the list. A similar method returns the sum of the list.
Part 1, cheated a little by using vim to strip down whitespace to single spaces with :%s/\s+/ /g. Then
Part 2, used the given input, although trimmed the operator line in vim in the previous manner.
2
u/PendragonDaGreat Dec 06 '25
[LANGUAGE: C# Csharp]
Code here
Once again I get to brush off a utility I haven't used in a couple years, this time my
ToColumnsfunction. Otherwise just straight iteration.2
u/TheZigerionScammer Dec 06 '25
[Language: Python]
Well this was certainly a tricky solution and I had to bust out the hacky solutions for it. For Part 1 I took one look at the input and thought "These numbers are positioned all over the place in each column. I'll need Python to strip out all that unnecessary whitespace." But once each line was separated it just meant going column by column and solving each math problem. Doing this with Python's lists is tricky since you have to keep track of multiple list subscripts, my first draft had the subscripts backwards before I caught it. I normally like formatting the data a better way but this worked for now.
Then Part 2 came around and I realize why the whitespace was so haphazardly placed, they were necessary because now the columns place matters for each number. So I actually had to retroactively change how the program parses the input and make a copy of it and retroactively change Part 1's code so it still worked. Part 2 was a little bit easier to code once I thought of how to do it, it just goes column by column, putting the 5 relevant characters into variables, checking if they're all blank at first, getting the sign, and then doing the appropriate math. I had a couple errors though, the first was a subscript out of range error which I realized was because the last line had some whitespace stripped out so it wasn't as long as the others. I don't like editing the input file itself so I added the
line to the code to make it work, luckily my last column had a 4 digit number so all of the other lines were the same length. It's every hacky solution, and I don't know if that's true for everyone's input so it's possible my code would fail on someone else's input if their last number column doesn't have 4 digits. I could add a check to dynamically do the same for all the lines to make them all the same length perhaps, or change the whole thing so it works like a grid instead of a list of strings but it is what it is now. Maybe after the year.
Paste
2
u/r_so9 Dec 06 '25
[LANGUAGE: F#] paste
My first solution for part 2 was using a recursive function to parse the numbers vertically (raw solution). After I got the right answer I cleaned up to use just Array and String manipulation. Interesting parts - a bit of functional programming for the operations, and the pipeline to solve part 2 (input is an array of lines):
2
u/guiambros Dec 06 '25
[Language: Python]
First day of numpy! And also functools and operators. I thought part 2 would be a pain, but it was easier than I expected.
Solution
2
u/Kehvarl Dec 06 '25
[LANGUAGE: Python3]
Well that was a ride! For part 1 I built a transposer to get each problem into a list, then a bit of code to perform the needed operations without using eval. That seemed fine.
Then part 2 hit. My transposer needed a complete rewrite, then it was wrong because I had already thrown away essential positional data when parsing, so I had the opportunity to simplify my parsing, write a really, really basic transposer, then write a tool to convert everything into problem lists, and then finally pass the problem lists to my problem handler.
For even more fun, I needed a +1 in my problem-builder for the Test, but had to remove it for the Input, so there's definitely something wonky somewhere in my parsing.
Part1 Part 2
2
u/Mikey_Loboto Dec 06 '25
[Language: JS] (Node)
GitHub
Not too proud of this one.
2
u/reddit_Twit Dec 06 '25
[LANGUAGE: GDScript]
gist
2
u/Eva-Rosalene Dec 06 '25
[Language: TypeScript]
Here, I can't omit parser "for brevity". It's the actual solution that is straightforward after you get data processed.
parser (I do two passes: first, scan each column top-to-bottom to get number and potentially operator, then go through columns left-to-right to construct expressions. Surely, task says "right-to-left", but addition and multiplication don't care)
solution
2
u/chickenthechicken Dec 06 '25
[LANGUAGE: C]
Part 1: https://github.com/PaigePalisade/AdventOfCode2025/blob/main/Solutions/day06part1.c
Part 2: https://github.com/PaigePalisade/AdventOfCode2025/blob/main/Solutions/day06part2.c
Just a problem about parsing nastily formatted inputs.
For part 1, I read the numbers into a table of integers, then read the operators in order, adding or multiplying the numbers in the corresponding column.
For part 2, I read the lines as strings, then I went column by column, constructing the numbers from their digits in the rows. Every time I ran into an operator, I added the subtotal to the total and switched "modes"
2
u/cicadanator Dec 06 '25
[LANGUAGE: Javascript - Node JS]
Part 1 I split the numbers into columns by splitting each row's string on spaces and eliminating blank values. This gave me easy to use columns. I then went through each column and got all of the numbers into an array. These were then joined together using the operator in the last row and run through an eval to get the equation total which was added to the final total.
Part 2 was similar to Part 1. The main difference was how to read the numbers form the file input. In this case I read each column of text one at a time. This allowed me to assemble each number and find each operator. I then used finding the next operator as a way to split each equation. Using the same method for array joining and then using an eval statement I was able to find the final total for part 2.
https://github.com/BigBear0812/AdventOfCode/blob/master/2025/Day06.js
2
u/RubenSmits Dec 06 '25
[Language: Kotlin]
2
u/Wayoshi Dec 06 '25
[LANGUAGE: CPython] paste
Sadly took me over 30 minutes into the problem, when debugging why some columns were parsing wrong no matter what I tried, to realize how critical the spaces in the input are for this one, which feels like an extreme rarity for AoC. I always strip the strings when getting numbers in my utility function, so I had to rewrite the parsing of each line from scratch for part 2.
When I finally got there I had fun making the whole part2 calculation a single comprehension like part 1, complete with an if-else for multiplying or summing each column, and looping over an
itertools.pairwisefor the right slice indexes.2
u/Meamoria Dec 06 '25
[Language: Kenpali]
Using AoC to test out my experimental minimalistic language.
Part 1
Part 2
This problem, built around sequences of fiddly transformations rather than fancy algorithms, is right in Kenpali's sweet spot.
Note that the "right-to-left" specification in Part 2 is a red herring, since both addition and multiplication are commutative and associative. So I just did everything left to right and got the same answer.
2
u/Practical-Quote1371 Dec 06 '25
[LANGUAGE: TypeScript]
GitHub
I'm running in GitHub Codespaces this year, it's been a fun experience being able to use multiple devices and get to the same code even before I push to the repo.
Shameless plug: I'm using my AoC Copilot package again this year. It does all the normal runner stuff, so the main differentiator is that is also pulls the examples out of the puzzles and runs my solution against those automatically before running against the actual input. It's been super helpful to eliminate bugs on the simpler examples before moving onto the input. And, the built-in search strategy has managed to find all 6 examples and solutions for both parts this year without any updates! (Full disclosure, I did make one adjustment for day 2 so that it would combine the example into a single row like the input).
2
u/kcharris12 Dec 06 '25 edited Dec 06 '25
[LANGUAGE: Python]
I split the input into columns by the locations of the math operators and by keeping the ranges of start and end locations in an array.
Then I used these ranges to perform the math in, building larger numbers as I find new ones within each row of the range.
A bit of debugging and print statements for this one. str.strip() taking away spaces, and incorrect indexing when trying to build a prefix sum within the (start, end) ranges.
https://github.com/kcharris/AdventOfCode2025/blob/main/Day6/answer2.py
2
u/BxW_ Dec 06 '25
[LANGUAGE: Zig]
Only minor refactor on my original solutions. I will optimize both the parts and post later. Only interesting thing about it right now is how little parsing I do and how little intermediate states there are.
paste
2
u/Jumbledswp Dec 06 '25
[LANGUAGE: C++]
I hardcoded it for 4 lines (idk if everyone has four lines but hope so)
(its also kinda repeating but i dont really care for it)
i fear this will happen though:
"From now on, the difficulty curve is going straight up." - Computer, "Can you draw every flag in powerpoint?", @DrZye
paste
2
u/Ok-Bus4754 Dec 06 '25
[Language: Python]
another easy day
https://github.com/Fadi88/AoC/blob/master/2025/days/day06/solution.py
part 1 just parsing
part 2 , just transpose and still easy parsing
p1: 700 us
p2: 850 us (extra for transpose i guess)
will port later to rust
2
u/semi_225599 Dec 06 '25
[LANGUAGE: Rust] Code
Used winnow for some parsing (not really necessary here, just a little more concise) and an existing
transposeutility from previous years.2
u/msschmitt Dec 06 '25 edited Dec 06 '25
[LANGUAGE: Python 3]
Part 1Part 2
I would have got part 2 a lot faster if I hadn't misread the instructions. I thought that column spacing still didn't matter, and we were supposed to right align the numbers before converting them. That was a bunch of code to toss in the bit bucket.
After understanding it properly, the code is just iterating through all the lines simultaneously, one column at a time, and building the number and operation.
There's no need to clean up the number formatting because it will just get evaluated as a string anyway.
2
u/PeaFun6628 Dec 06 '25
[LANGUAGE: C++]
Here is the code: https://github.com/Shoyeb45/CompetitiveProgramming/blob/main/AdventOfCode/Y-2025/D6-TrashCompactor.cpp
Approach:
Part 1:
- Parsed the input and made separate list of numbers given column wise
- Then for each column, calculated sum or multiplication according to given operation.
Part 2:
- Part 2 took me some time to understand the question.
- Now the hard part was to keep the original input as it is. So that we can know the order of the numbers in one column
- Used getline function in c++ to take input of entire line and store it in vector.
- Then if we carefully observe then we just need number from one operator to another operator.
- Let i is index of the current operator and j is the index of next column operator.
- Then for each row from i = 0 to n - 1, where n is the number of rows in input, we can parse the numbers and form one complete number.
- The code will work in any scenario as long as input is given in structured format.
2
u/wheresmylart Dec 06 '25 edited Dec 06 '25
[LANGUAGE: Python]
Ugly fiddling with matrix transposition is ugly! zip() is your friend!
Processed part 2 in reverse order because it was easier that way.
Paste
Edit: Corrected link
2
u/se06745 Dec 06 '25
[LANGUAGE: Go]
https://github.com/omotto/AdventOfCode2025/blob/main/src/day06/main.go
2
u/[deleted] Dec 06 '25 edited Dec 06 '25
[Language: Haskell]
Part 1
Part 2
Part 1 - 7.49 ms, Part 2 - 5.56 ms
For Part 1, read the numbers line by line into a map indexed by column. Then for each column, apply the op to the numbers and add this to the total.
For Part 2, read the entire grid into a 2D array of characters indexed by row and column. Then iterate from the right (columns - 1) down to 0. If the column is all spaces, skip it. If the column contains a number with no operators, convert it to an integer and push it onto a stack. If the column contains an operator at the end, push the last number onto the stack, apply the op to the whole stack, and then add the result to the total.
2
u/TiCoinCoin Dec 06 '25
[Language: Python]
Late to the party: day 6
Not that difficult, but it's funny to handle the data. I had to rework the parsing to keep the white spaces and then be able to transform the problems in part 2.
2
u/FCBStar-of-the-South Dec 06 '25
[LANGUAGE: Scala/Excel]
Feedback on Scala code absolutely solicited.
Was going to write some code for part 1 but then realized that it is absolutely trivial to do in Excel (or any other spreadsheet). Got the answer quickly that way before moving on to part 2. Don't love the parsing logic but it works.
2
u/Chungus1234 Dec 06 '25
[LANGUAGE: Elixir]
Enum utils in elixir made this one pretty easy. Solution: https://github.com/moore-andrew05/AoC2025-elixir/blob/main/lib/day06.ex
Name ips average deviation median 99th %
Day06.part1 1.67 K 0.60 ms ±7.85% 0.59 ms 0.72 ms
Day06.part2 0.42 K 2.36 ms ±12.28% 2.24 ms 2.97 ms
2
u/leonmarksmith Dec 06 '25
[Language: Python]
Part 1
Part 2
I get people go for speed to submit these and it's throw away code but other python submissions always feels so far away from anything I would write in real life?
2
u/ruinedme_ Dec 06 '25
[Language: JavaScript]
https://github.com/ruinedme/aoc_2025/blob/main/src/day6.js
Had to do a little refactoring on the parsing side for part 2 since column alignment became significant. Which also gave the benefit of moving from column wise to row wise 2d array which made processing simpler.
I noticed that the row with the op symbols were all left aligned regardless of alignment for the numbers. So i just scanned the op string up to the next symbol and pulled out the substrings for each number in that column into a row. The reconstruction of the numbers in part 2 feels a bit jank but it works.
2
u/Goatmancer Dec 06 '25
[Language: C#]
A parsing problem. Fun!
Blog post
Github
2
u/Szeweq Dec 06 '25
[LANGUAGE: Rust]
Well, my "individual problem" was trying to read the part two example with a naked eye. My solution takes the input parsing at the very late stage. Yes, these two parts are just input parsing.
https://github.com/szeweq/aoc2025/blob/main/day06/src/main.rs
2
u/Main-Reindeer9633 Dec 06 '25
[LANGUAGE: SQL] (Dialect: PostgreSQL)
There is no built-in aggregate function for multiplication, so I got a chance to add one, which made part 1 very easy. Part 2 was pretty straight forward, but it did run for 5 seconds before I added a
MATERIALIZEDin the right place, which cut it down to .4 seconds – sometimes the query planner makes strange choices.paste