Advent of Code or whatever

Doing Advent of Code like every year. Last year I wrote blog posts every day but idk if I have the energy for that this time around; my goal this year is to produce at least one or two interesting gifs of not necessarily solutions, but something relevant to the solution. But since those are exponentially more effort than just solving it, I’m not actually committing lmao…

Anyway, here’s my day 1.

(as an aside, lol:)
Discourse warning banner: Title must be at least 15 characters

4 Likes

Anchor tag with no href

God, I thought my browser was malfunctioning.

4 Likes

Lol that’s funny, I did give it something to point at. I guess it didn’t like the lack of https??

The raw malfunctioning markdown for the link

2 Likes

i can see if i can change that :+1:

2 Likes

And day 2.

Part 2 spoilers

I was briefly considering writing my detection in a way that’s robust against removing any one element, but it’s honestly just much easier (and way fast enough) to simply try every possible one-element-removed list.

Excited to participate for the first time this year! My friend said AoC really helped him learn a lot, so hopefully it does the same for me c: I’ll be doing it in Python

2 Likes

Yep, I learned multiple languages using it over the years, as well as (Neo)vim last year! It just gives you something relatively low stakes but concrete to do, which is great practice.


On that note, here’s my day 3.

I originally had a neat iterator-based solution for part 1, because if you really don’t care about anything but the muls, you can liberally discard stuff left and right. But after I wrote out the full version for part 2, I fused the solutions because that’s neater. Old solution here though, for posterity (thanks, Neovims insane undo feature!):

Previous part 1 code
pub fn one(input: &str) -> crate::Result<i32> {
    Ok(input
        .split("mul(")
        .filter_map(|t| {
            let (t, _) = t.split_once(')')?;
            let (a, b) = t.split_once(',')?;
            let (a, b) = (a.parse::<i32>().ok()?, b.parse::<i32>().ok()?);
            Some(a * b)
        })
        .sum())
}

Ok edit, because after writing this lil blurb I had a brainwave and wrote a much neater and shorter version based on the “previous part 1 code”, and now I’m in a much better mood than before lmao

2 Likes

And day 4. This finally pushed me to write my own implementation of a carthesian product (ie. all combinations of elements from two lists). Also even though it’s technically redundant, I wrote a carthesian product for three lists, too–just for ergonomics.

I use this product all the time in code I write, and it’s available in a popular extension library, but I figured in the spirit of the challenge I should handroll it.

1 Like

That’s day 5 done, too. I started out not particularly liking my solution, it felt a bit too verbose for what I’m doing, But it’s fine actually, and I actually really enjoy the main trick I did in part 2.

Still been doing it, day 6 and day 7.

6 kind of had teeth for a day 6; and day 7 wasn’t so bad except for the part where I did it really badly at first because I was in a rush to go play PoE2 lol. Now that I got that out of my system a little bit (that’s a lie, I’m going right back in a sec), I realized that this is exactly the sort of thing that you can easily do recursvely…