Find the shortest route on an ASCII road You want to find the length shortest path between two points, on an 2d ASCII "map". The roads are made up of + characters, and the two endpoints are represented by #s (not counted in the length). This road can be arranged in any way, and any other characters can be ignored. You can assume the endpoints will always connect to each other through roads.

Examples:

Output: 1

#+#


Output: 5

   #+
+   +
++++++
   +
   #


Output: 8

++++#+++
+      +
+      +
++#+++++


Output: 4

#+++
++++
+++#


Output: 2

+++++
+   +
+#  +
+++#+
   +
 +++


Undefined output:

##


#   +++#
+    +


#+++#
    +
    +
    #


#++
  +


Rules:


You can take input as a 2d array, matrix, string separated by newlines, etc.
Output should be a number
Can be a snippet, function, or full program
You can represent one endpoint with a different character if necessary
Python 3, 163 bytes



def f(g,s=[]):w=len(g[0])+1;k=' '.join(g)+w*' ';*p,x=s or[k.find('#')];return' '&lt;k[x]and{x}-{*p}and[min(f(g,s+[x+a])or len(k)for a in(-1,1,-w,w)),len(p)]['+'&lt;k[x]]


Try it online!

Uses # for start and @ for end. Finds all paths along + and returns the shortest. Each path ends when either a space is encountered, the range is outside the box or a previous position is visited.