23
๐ฌ - 2026 DAY 3 SOLUTIONS - ๐ฌ
(programming.dev)
An unofficial home for the advent of code community on programming.dev! Other challenges are also welcome!
Advent of Code is an annual Advent calendar of small programming puzzles for a variety of skill sets and skill levels that can be solved in any programming language you like.
Everybody Codes is another collection of programming puzzles with seasonal events.
Solution Threads
| M | T | W | T | F | S | S |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 |
Icon base by Lorc under CC BY 3.0 with modifications to add a gradient
console.log('Hello World')
Rust
Spent most of the time writing a 2D grid abstraction and writing up the solution, rather than actually solving the problem. In fact, had the problem solved before Day 4 came out, and just took until now to figure out a reasonable way to explain it in my writeup.
Basically: do a double for loop through the set of all trees. For part 1, the two trees should be the top-left and bottom-right corners of the square (check to make sure they're properly diagonal from each other, and that the other two corners have trees). For part 2, the two trees should be consecutive corners of the square (find the other two corners by continuing the walk around the square, and make sure they have trees). In part 2, we need to divide by 4 to account for duplicates (each square is counted once per side). Solution completes "instantly" in release mode, so I'm pretty satisfied with the performance, at least compared to a lot of other people in this thread.
Relevant parts of code
For pt2, another way to handle/prevent duplicates is to remove the trees as you go. Most of my performance issues went away in release mode, i got pt2 to 2-3ms, which is good enough. Would prefer <1ms, but further optimising is basically just taking someone elses solution, so I'll live with my inadequacy :D