title: Recursion through 2D Array
body: <p>I am trying to recursivley navigate through a 2d array jumping to a row with the index of a coloumn in which I can find a value. </p>
  
  <pre><code>                                 # 0  1  2  3 
          sample_array_of_arrays = [[0, 1, 1, 0], #row 0
                                    [0, 0, 1, 1], #row 1
                                    [0, 0, 0, 0], #row 2
                                    [0, 0, 0, 0]] #row 3
  </code></pre>
  
  <p>This means for the above example: There is a value in row0 at position 1. So I go to row1. I find a value at position 2 so I go to row 2. I dont find any values in row 2 so I terminate. I do this for all possible combinations and end up with following:</p>
  
  <p>row0 -> row1 -> row2</p>
  
  <p>row0 -> row1 -> row3</p>
  
  <p>row0 -> row2</p>
  
  <p>I have tried a variety of different recursive approaches, but I cant figure it out. This works for one combination (row0 -> row1 -> row2)</p>
  
  <pre><code>def rec_go_through_grpah(row,index):
  
      if sum(sample_array_of_arrays[row])==0:
          print("row " +str(row) + "    reached dead end")
          return
      else:
          while index &lt;= len(sample_array_of_arrays[row]):
              current_element = sample_array_of_arrays[row][index]
              if current_element==0:
                  rec_go_through_grpah(row, index+1)
              else:
                  print ("row "+str(row) + "-&gt;")
                  rec_go_through_grpah(index,0)
  
  if __name__=="__main__":
  
      sample_array_of_arrays = [[0, 1, 1, 0],  # row 0
                                [0, 0, 1, 1],  # row 1
                                [0, 0, 0, 0],  # row 2
                                [0, 0, 0, 0]]  # row 3
  
  
      rec_go_through_grpah(0,0)
  </code></pre>
  
  <p>It is an infinite loop and the output is </p>
  
  <pre><code>row 0-&gt;
  row 1-&gt;
  row 2    reached dead end
  row 1-&gt;
  row 2    reached dead end
  row 1-&gt;
  row 2    reached dead end
  row 1-&gt;
  row 2    reached dead end
  ...
  </code></pre>