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

  • CameronDev@programming.devOPM
    link
    fedilink
    arrow-up
    4
    ·
    2 days ago

    I like this approach much better than mine, I waste so much time walking around the grid to find the next corner, instead of checking the known trees.

    • addie@feddit.uk
      link
      fedilink
      arrow-up
      3
      ·
      2 days 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.

        • janAkali@programming.dev
          link
          fedilink
          arrow-up
          3
          ·
          2 days 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.devOPM
            link
            fedilink
            arrow-up
            1
            ·
            edit-2
            2 days 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!