title: How to find shortest path in X*Y grid
body: <p>I have a grid N*M in Python.</p>
  
  <p>where</p>
  
  <p>"X" represents the border, </p>
  
  <p>"1" represents current position, </p>
  
  <p>"2" represents finish, and</p>
  
  <p>"3" represents forbidden locations.</p>
  
  <p>The last thing is that (imagine you're a car) you can go only straight or right.</p>
  
  <p>Example 3x3 except borders:</p>
  
  <pre><code>[X,X,X,X,X]
  [X,2,1,0,X]
  [X,0,3,0,X]
  [X,0,0,0,X]
  [X,X,X,X,X]
  </code></pre>
  
  <p>Another example:</p>
  
  <pre><code>[X,X,X,X,X]
  [X,2,0,0,X]
  [X,3,3,1,X]
  [X,X,X,X,X]
  </code></pre>
  
  <p>Or another:</p>
  
  <pre><code>[X,X,X,X,X,X,X]
  [X,0,2,0,0,0,X]
  [X,0,3,0,3,0,X]
  [X,0,0,0,0,0,X]
  [X,0,3,0,3,0,X]
  [X,0,3,1,3,0,X]
  [X,X,X,X,X,X,X]
  </code></pre>
  
  <p>Do you have any suggestion for concrete script that will find the fastest way?</p>
  
  <p>And if there's not, print("No solution")?</p>
  
  <p>Thank you very much!</p>
  
  <p>To help you understand these situations:</p>
  
  <p><a href="https://i.stack.imgur.com/dS3or.png" rel="nofollow noreferrer">pictures of examples 1 and 2</a></p>