Well, actually, it might put the the operation at the back. So you might need to do a one rotate after you uh look at that. Everybody loves a rotate. And also, too, you need the splitting functions, which I have uh in a string library. And actually I borrow the names of uh words and unwords from Haskell. The major difference is that I'm evaluating uh You're evaluating a string. You're doing a reduction on the integers. Yeah, yeah. Very nice though. Still like uh 90% the same. Yeah, exactly. Welcome to ADSP the podcast, episode 268, recorded on December 22nd, 2025. My name is Connor, and today with my co-host Ben, we chat about Advent of Code 2025 in C and BQN day six.
BenYou should try day six. I recommend that you in particular should try day six as an array language programmer.
ConorSo day six, it's funny. I don't know at what point, but I was kind of sad. I was kind of sad at some point in the last couple of weeks because I had given up so quickly. And I was like, oh, you know, having a code. I might have been on a plane or something, and I was just like, you know, maybe I should go look. And I the first thing I was looking for was to see was there a huge drop-off after day three? I was hoping for my biases to be confirmed and that like they really messed up with day three, and that it just, you know, half as many people on day four were doing it. That was not the case. But then I I went to look at was there a day that was easier? Because in years past, every once in a while, they have like a day five or six or seven.
BenYeah.
ConorAnd uh and you're like, oh, this is much easier if you if you know the the technique or whatever.
BenRight. Well, and the difficulty is definitely not linear, right? Eric has said this. Some sometimes he throws in an early one, which is quite difficult.
ConorYes.
BenAnd quite often a later one will build on what came before. Interestingly, there's often also a sort of cellular automata thing going on. There's they're quite common for advent of code puzzles. And I think day four was sort of like yeah, day four was sort of like that, but there wasn't there wasn't a later one which built on it. Anyway, carry on. What are you gonna say about day six?
ConorWell, no, I was gonna say so day six was the day that I had cherry picked. Um I didn't actually go and solve it, but I did think to myself, at least for part A, I'm curious if you can tell me what part B is. But part A could be solved very, very cutely by basically just like transposing the matrix, and then you have a uh evaluate primitive basically in all arranged uh array languages, where if you just construct a string that is a valid program, you can just execute it. So all you would need to do is insert a slash after the operation, which would be pretty easy, right? The the uh binary operator. Well, I guess we should explain the problem if we're gonna chat about this a bit. Uh do you want to explain it? Um because you're the one that actually did it.
BenUh I was just looking, I was just looking at it and not paying attention to what you said for the last 30 seconds. Sorry. So go why don't you go ahead and explain?
ConorYeah, I put put the cart in front of the horse once again, uh, for like the sixth time uh in this conversation because I start explaining how you solve it without even mentioning anything about the problem. So uh you're gonna say something though.
BenBut you're right, like day six, if you have transpose. Transpose is a big workhorse for day six. Big workhorse. Yeah. Um and I learned transpose in Python. Oh yeah, yeah. The uh star star splat, whatever. Uh zip of star. Yeah, yeah. Yeah. Actually, I looked on um Google Translate and I Oh, did you?
ConorBecause I was gonna say, is I I'm pretty sure I was literally just to bring it up. I don't know if it's there. I think it is. Maybe it is. I didn't know you want to search for. If you type transpose and then you uh uh oh no, it's not. Interesting. Pythons Oh actually wait. If I go show expressions, there it is. It's hidden. Here, let me share my screen for a second. Oh, okay. We'll share window next time. Maybe I'll maybe I'll tweet this out. Um so if the default is turned on, that's kind of uh evil of me. So you go to if you search transpose on Google Translate, a website I built, uh except if you spell it correctly, it brings up by default every function that matches that uh textual name. But if you click on any, and you can see that all of these have the exact same semantics because they're all the same color. Uh if you click on one of these now, it'll show all of the functions across languages, regardless of the name that match the semantics. And D calls it transposed. Uh Moon, which is uh esoteric language made by uh an individual that wanted to add it, calls it zip, and q calls it flip. So I thought for sure I added this, but that's because I decided to hide um expressions and third-party libraries. Oh the zip star is not actually a function by, it's an expression. Uh and so if you do that, zip star, sure enough, is the very last thing at the bottom uh from Python. Because when you said that, I was like, I'm pretty sure I added that to Google Translate. However, it is hidden.
BenOkay, makes sense. But I didn't see it. Right. Because star is, of course, just for people who don't know Python, star is kind of the destructuring operator, right? Which which sort of takes the list to a pack of elements, if you like. And then so if you have a list of lists and you say star of it, you get the pack of lists, and then you zip them, and of course that gives you the first one of each, followed by the second one of each. So it's transpose.
ConorIt's a magical incantation that somehow maps to transpose. Uh but uh but yes, day six, so it gives you a uh table of numbers that are space delimited, and uh at the bottom of each column is a binary operation, either multiply or plus. So the asterisk or the plus sign. And it basically just asks you to, based on that binary operation, compute the reduction of that column and uh return the sum of all those values. And so in BQN, a plus or multiply reduction is literally just, I guess you would have to replace the asterisk with the multiplication symbol. I I didn't realize that. But you could just add a slash to each of those things, and then that becomes a reduction. And if you transpose it, and I guess maybe transposing this, no, yeah, it will put the actually it might put the the operation at the back. So you might need to do a one rotate after you uh look at that. Everybody loves a rotate, and also too, you need the splitting functions, which I have uh in a string library, and actually I borrow the names of uh words and unwords from Haskell because they're so nice and so useful. But you could basically do a words on each line, put that in a matrix, and it has to be strings at that point because you've got your operation, do a one rotate on that, or do a transpose, then a one rotate that gets your binary operations at the beginning, and then replace the asterisk with a multiplication, add a slash, do an unwords on each row of your matrix now that turns it back into a valid BQN expression in the form of a string, and then just call the system BQN function, which is effectively an evaluate. And uh anyway, so I did uh I did look at this and I solved it in my head. Uh I didn't actually solve it. Uh, but then I was very curious, not curious enough to actually write the solution to what is part B and is it uh as nice to solve as part A.
BenSo I did the same as you just outlined, except in Python. The one rotate, the transpose, and then I take the head and the tail. So the head after the one rotate, the head is the operator, and the tail is the thing to put the reduction list. And then I just use the operator string to look up into an array of two functions plus and multiply.
ConorAnd then do you do you do you have like an eval function in Python?
BenNo, no, because because sorry, it's a it's a map lookup. It's a dictionary, right? So star is is the function operator.mull. Yeah. Right? And plus is operator.add. And then you just reduce using that operation across the list. Using like the func tools reduce?
ConorUh yes. And then just turning like uh each string into an int. Each string.
BenYeah, each string's already an int. Yeah, sorry, no, I'm I map I map int across the string, across the list, across the tail of the list.
ConorThe major difference is that I'm evaluating uh You're evaluating a string. You're doing a reduction on the integer. Yeah. Yeah, yeah. Very nice though. Still like uh 90% the same. Same, yeah, exactly. And then what what was part B? So I don't actually this is a surprise for me uh because I never I never did part A, actually. I just, like I said, solved it in my head.
BenRight. Well now you can code up part A in you know five minutes. Um Part B is like part A, but more tricky transposing, because it turns out that not only are the So the matrix itself in part A was transposed. In part B, the I don't think I'm gonna be able to explain this exactly, but the numbers are within the column, have to be read column wise instead of row wise, if you like. So so you've got if you've got a sum of like three three-digit numbers, then instead of being those three-digit numbers, they are the column-wise three-digit numbers.
ConorRight. So I mean in the first column of the example, the numbers are one, two, three, hundred twenty-three on the first line, forty-five on the second line, and six on the third line. So if you transpose that, the numbers are now going to be three hundred fifty-six, twenty-four, and one, something like that. Yes. Yeah. What if are you guaranteed that you have contiguous uh stretches? Or are there's is there a potentially like a three-digit number followed by a one-digit number followed by a three-digit number?
BenThey can change in their length, yes. You have to take account of Yeah, you have to sort of read them in at some point as columns, because each each column of numbers is delimited by a column of spaces. But within a column, the numbers can be either left justified or right justified, they can be three digit, two digits, one digit, that sort of thing.
ConorIf you have a gap in between two digits, do those just get compacted to basically so if you have in a given column, no, those stay as separate numbers.
BenAnd and the number has to stay in its right in its correct justification in the column in order to treat each digit as its correct place value in the transposed numbers. So there's a little bit of jiggery pokery around that. Well, I mean that makes it much more tricky. Because if you can just split Yes, that's and that's the tricky part.
ConorYou can't just split them and collapse all the spaces into one space. Yeah. If you do your Haskell words, you know, put them in a column and then kind of reconstruct the numbers, you know, that's actually not too tricky. But if you need to keep the alignments respective of where the spaces are, that is now you need to like take a knife and cut out your numbers and keep them that way. That is much less trivial. But interesting nonetheless. Um how did you do that one?
BenUh very similarly to the first one, except with the input processing slightly different. Uh let's see. I yeah, I've postponed the split, like we were just saying. So I read it, I read the input line by line. And for the first star, I just go ahead and split the lines at that point. For the second star, I what did I do? I had to figure out. Yeah, I have to figure out where the spaces line up.
ConorRight. Well, I mean, are we is it given that because by the example, if we just look at the binary operations, it looks like one before the next binary operation is the column. Is that is that the case?
BenSo if you transpose the whole thing for the second part, then you turn columns of spaces into rows of spaces. And they're easy they're much easier to detect. That's a nice little trick. That's what I did. Very cute. So then you then you know then you sort of automatically uh detecting a row of spaces is just all off, right? So much easier than the column of spaces. So once you've transposed, then you uh effectively get the blocks of numbers for free, and then you can do your further transposition and whatever it is.
ConorVery neat. I will say, a much more fun, nicer problem than day three. Unless if you're in C. And when you have max element, and in that case, uh maybe day three is nicer.
BenI can send you my I solved day six in Python, and there's the uh solution.
ConorThat's pretty nice. I mean I would have done uh import operator as op in order to save yourself uh six characters there on uh yeah you can see on line 32 where I detect the rows of spaces. I mean that's a perfect uh perfect space a perfect uh spot for an array language reduction uh uh space equals not all.
BenIs there uh so that's actually my ch I wrote chunk as a as a generator as you can see, so I'm yielding each chunk. Oh, I see, I see, I see. So that predicate is basically when the chunk ends, which is when the or at least that predicate is true while the chunk is still going. And then as soon as that predicate fails, you're on a row of spaces, and it's time to start the next chunk.
ConorYeah. Well, maybe uh maybe before this uh gets released, I'll I'll code up a BQN version uh for folks to see the uh the comparison. Alright, well we're we're 30 minutes past. We knew this was gonna happen. And I still feel like we've brought probably got a ton of stuff that we can uh we could have chatted about. We'll have to save it for uh another time. Yeah, I mean, happy holidays, not just to you, but uh everybody listening. Likewise. I mean, at this point, actually, now I don't know, maybe it's the new year and this is part two or something of this. Because I'll I'm not gonna drop a two-hour podcast. Uh this will be happy new year to January 15th or whatever it is. Yeah, yeah, yeah. Well, I'll hopefully I don't know how I'm gonna dice it up, but I think I'll I'll release an hour episode uh this this Friday, but then so it'll probably be cut into three. How how I'm gonna do that, I'm not exactly sure, but um yeah, it's been good to catch up.
BenYeah.
ConorDo you have plans in 2026 yet to a conference attend? Um or that's a the down the road decision.
BenUh it's a down-the-road decision. Um, I suspect I won't be traveling a whole lot. Oh, right, yes. Um so my plan, my default plan is probably C now and CPPCon.
ConorOkay. All right. Well, we will uh if not at a conference, we will at minimum get the chat uh online. Yes. Uh hopefully we will cross paths at some point.
BenHope so.
ConorBe sure to check these show notes either in your podcast app or at adspthepodcast.com for links to anything we mentioned in today's episode, as well as a link to a GitHub discussion where you can leave thoughts, comments, and questions. Thanks for listening. We hope you enjoyed and have a great day. I am the anti Bryce. Um