Portal Maze Shortest Path
Mathematica (344)
Bonus: highlighting of the path
n = 10;
m = RandomChoice[{6, 3, 1} -&gt; {0, 1, 2}, {n, n}];
m[[1, 1]] = m[[n, n]] = 0;

p = FindShortestPath[Graph@DeleteDuplicates@Join[Cases[#, Rule[{ij__}, {k_, l_}] /; 
      0 &lt; k &lt;= n &amp;&amp; 0 &lt; l &lt;= n &amp;&amp; m[[ij]] != 1 &amp;&amp; m[[k, l]] != 1] &amp;@
   Flatten@Table[{i, j} -&gt; {i, j} + d, {i, n}, {j, n}, {d, Tuples[{-1, 0, 1}, 2]}], 
  Rule @@@ Tuples[Position[m, 2], 2]], {1, 1}, {n, n}];

Grid@MapAt[Style[#, Red] &amp;, m, p]
If[# &gt; 0, #-1] &amp;@Length[p]


I create the graph of all possible movies to neighbor vertices and add all possible &quot;teleports&quot;.