Optimization in matrix ?

I have matrix[4][4] for example:
' *  '
'  * '
'     '
'     '
enter in matrix(for example) with coordinates [0][0]
and exit [0][3].
How to find optimizing way from enter to exit ?
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

yairyConnect With a Mentor Commented:
if there are no blocks between
the enter and exit point:
I would calculate each step the Length
from the immidiate neighbour points to me to the exit point.
I would choose the shortest length each time.

If there might be block, it isn't as simple.
one should can use Backtracking
to find the path.

heres a recurse "rough" definition:

f(location, matrix)
  if you are at the enter pos and have
  nowhere to go - quit, failer.
  if you are in the Exit point -
  quit, Success.
  if you don't have any place to go
  (all is block (except the from where
  you came)) mark the place as DeadEnd.
  <do nothing, the recurse will pop you
  to the prev. position>
  call f(Location, matrix) for all
  free places that aren't blocked or a dead end.

Any questions ....

What do you wish to optimize?
What you want is a maze-solving solution, not a matrix-solving solution.  A matrix is just a way of storing/representing a maze (such as a minefield).

The solution will depend on whether you allow wrapping, etc.  We need the rules.
All Courses

From novice to tech pro — start learning today.