#AdventOfCode #Day7 with #rust
-
#AdventOfCode #Day7 with #rust
pretty straightforward, but I hit a weird issue: I cannot use a loca variable for a row of my grid while iterating, otherwise it complains I'm mixing mutable and immutable borrowings.
And yet, using an index directly makes the compiler happy? Why?
I suspect the indexing is hiding stuff, and the fact this compiles means "this may explode at runtime, idk" and not "this will work fine".https://gist.github.com/riffraff/05bbbf38100697d88410534238f43c55
-
#AdventOfCode #Day7 with #rust
pretty straightforward, but I hit a weird issue: I cannot use a loca variable for a row of my grid while iterating, otherwise it complains I'm mixing mutable and immutable borrowings.
And yet, using an index directly makes the compiler happy? Why?
I suspect the indexing is hiding stuff, and the fact this compiles means "this may explode at runtime, idk" and not "this will work fine".https://gist.github.com/riffraff/05bbbf38100697d88410534238f43c55
mh, if claude is to be believed, the index one works cause we have a single-expression borrow of the value in grid[nrow] followed by a _copy_ of the value in grid[nrow][ncol].
I am not sure this is true, but I've learned that indices work and that is good enough for now. -
#AdventOfCode #Day7 with #rust
pretty straightforward, but I hit a weird issue: I cannot use a loca variable for a row of my grid while iterating, otherwise it complains I'm mixing mutable and immutable borrowings.
And yet, using an index directly makes the compiler happy? Why?
I suspect the indexing is hiding stuff, and the fact this compiles means "this may explode at runtime, idk" and not "this will work fine".https://gist.github.com/riffraff/05bbbf38100697d88410534238f43c55
@riffraff Fascinating. I didn’t make a grid at all. Instead for part 1 I just maintained a hash set of ints where there was a tachyon, and then just iterated through each line and created two new ones whenever there was an overlap with the splitters.
Second part I used a dfs-inspired approach with memoization/dynamic programming.
https://github.com/teotwaki/aoc/blob/main/2025/07/src/lib.rs
-
@riffraff Fascinating. I didn’t make a grid at all. Instead for part 1 I just maintained a hash set of ints where there was a tachyon, and then just iterated through each line and created two new ones whenever there was an overlap with the splitters.
Second part I used a dfs-inspired approach with memoization/dynamic programming.
https://github.com/teotwaki/aoc/blob/main/2025/07/src/lib.rs
@teotwaki I used a hash in my ruby version for part 2, but I didn't think of the DFS/DP idea, nice