MATLAB: Code of trace path

trace

hi, say have this array: x=
1 0 0
0 0 0
0 0 0
i want anyone help me to write algorithm to trace any path begin from (1,1) and have to stop in (3,3), but when passing position such x(i,j),x(i,j) will be =1 , otherwise will be zero where sum(Xij)<=2 if j=1:3 or sum(xij)<=2 if i=1:3.
it is like sequence alignment algorithm, but I do not want use dynamic programming algo. to do this task. I wrote code but did not get the exact result who can help me? Thanks in advance

Best Answer

Your conditions appear to translate as:
  1. first move can be in any of the three directions (random choice of 3)
  2. after that, the next move cannot be in the same direction as the one immediately previous (random choice of 2)
  3. when you reach the bottom or right edge if you do not already happen to be at the bottom right corner, you are exactly one space away and your move is forced and legal.
I have not proven that you cannot intersect the edges except for the target or one space from the target, but my mental modeling is that it is the case for square matrices under those move restrictions.