Day 16: Reindeer Maze

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

  • Pyro
    link
    fedilink
    arrow-up
    1
    ·
    3 hours ago

    Interesting, how would one write such a finder? I can only think of backtracking DFS, but that seems like it would outweigh the savings.

    • Acters@lemmy.world
      link
      fedilink
      arrow-up
      1
      ·
      edit-2
      2 minutes ago

      ah well, my idea is at high level view. Here is a naive approach that should accomplish this. Not sure how else I would accomplish this without more thought put in to make it faster:

      [ Paste ]

      edit: whoops, sorry had broke the regex string and had to check for E and S is not deleted lol

      This is how the first example would look like:

      ###############
      #...#####....E#
      #.#.#####.###.#
      #.....###...#.#
      #.###.#####.#.#
      #.###.......#.#
      #.#######.###.#
      #...........#.#
      ###.#.#####.#.#
      #...#.....#.#.#
      #.#.#.###.#.#.#
      #.....#...#.#.#
      #.###.#.#.#.#.#
      #S###.....#...#
      ###############
      

      This is how the second example would look like:

      #################
      #...#...#...#..E#
      #.#.#.#.#.#.#.#.#
      #.#.#.#...#...#.#
      #.#.#.#####.#.#.#
      #...#.###.....#.#
      #.#.#.###.#####.#
      #.#...###.#.....#
      #.#.#####.#.###.#
      #.#.###.....#...#
      #.#.###.#####.###
      #.#.#...###...###
      #.#.#.#####.#####
      #.#.#.......#####
      #.#.#.###########
      #S#...###########
      #################
      

      for this challenge, it will only have a more noticeable improvement on larger maps, and especially effective if there are no loops! (i.e. one path) because it would just remove all paths that will lead to a dead end.

      For smaller maps, there is no improvement or worse performance as there is not enough dead ends for any search algorithm to waste enough time on. So for more completeness sake, you would make a check to test various sizes with various amount of dead ends and find the optimal map size for where it would make sense to try to fill in all dead ends with walls. Also, when you know a maze would only have one path, then this is more optimal than any path finding algorithm, that is if the map is big enough. That is because you can just find the path fast enough that filling in dead ends is not needed and can just path find it.

      for our input, I think this would help as the map should be large enough.