home.social

#day04 — Public Fediverse posts

Live and recent posts from across the Fediverse tagged #day04, aggregated by home.social.

  1. CW: Advent of Code 2025 Day 4 solution

    Day 4 done. This was probably the easiest one so far, but it might be because I'm so used to the grid problems from previous years.

    I felt like just doing the count for part 1 would end up forcing me to rewrite something, so I returned the coordinates, hoping they'd come in handy for part 2. Fortunately, they did, and my part 2 was a 10-second addition, just adding a loop around the part 1 function. The whole thing runs in about 86 milliseconds. I could probably optimize it by storing a neighbor count in each live cell, decrementing those in accessible neighbors on each removal, and maybe keeping them in a sorted vector via Rc<RefCell> or an internal Cell, but I'm happy with this right now.

    Edit: I ended up doing the optimization anyway

    This runs in 10ms now. It might even run a bit faster if I make the rolls keep track of their neighbors with weak refs too, to prevent lots of extra neighbor lookups in the HashSet. I'll experiment with that a tiny bit, but I'm not going to spend all too much effort on it, and probably won't add an update unless it is a big speed boost.

    #AdventOfCode #AdventOfCode2025 #AdventOfCode2025Day4 #AdventOfCode2025Day04 #Day4 #Day04 #Rust #RustLang #Programming #codingchallenges