23

Day 3: Foggy Forest

Megathread guidelines

  • Keep top level comments as only solutions, if you want to say something other than a solution put it in a new post. (replies to comments can be whatever)
  • You can send code in code blocks by using three backticks, the code, and then three backticks or use something such as https://topaz.github.io/paste/ if you prefer sending it through a URL

FAQ

you are viewing a single comment's thread
view the rest of the comments
[-] addie@feddit.uk 3 points 1 day ago

Indeed; very nice. Saves wasting loads of time checking for 'every possible grid and skew' like I was doing, since it only checks possibilities, and would scale very well to truly enormous grids of trees.

[-] CameronDev@programming.dev 3 points 1 day ago

I tried it and my code got slower :(

Mostly because the hashset lookup is just brutally slow for some reason.

[-] janAkali@programming.dev 3 points 1 day ago

hashset lookup is just brutally slow for some reason

You're probably doing way too many hashing checks, my version prunes a lot of incorrect pairs (where second corner is above or to the right of the first) cheaply.

But you also don't need hashset here at all, you can just index into the existing grid e.g. grid[y][x] == '#'.

[-] CameronDev@programming.dev 1 points 1 day ago* (last edited 1 day ago)

Priming the hash checks didnt help, but now you mention it, just indexing into the grid is very obvious...

Edit: down to 22ms, completely dropped hashset. Still not quite happy, but getting there!

this post was submitted on 03 Dec 2026
23 points (100.0% liked)

Advent Of Code

1278 readers
56 users here now

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.

EC 2025

AoC 2026

Solution Threads

M T W T F S S
1 2 3 4 5 6
7 8 9 10 11 12

Visualisations Megathread

Rules/Guidelines

Relevant Communities

Relevant Links

Credits

Icon base by Lorc under CC BY 3.0 with modifications to add a gradient

console.log('Hello World')

founded 3 years ago
MODERATORS