title: how is this code working? backtracking and recursion
body: <p>This is a working code that solves the sudoku:</p>
  <pre><code>def is_valid(board, row, col, num):
      for i in range(9):
          if board[row][i] == num:
              return False
  
      for i in range(9):
          if board[i][col] == num:
              return False
  
      box_row = (row - row % 3)
      box_col = (col - col % 3)
  
      for i in range(3):
          for j in range(3):
              if board[box_row + i][box_col + j] == num:
                  return False
      return True
  
  def solve(board):
      for row in range(9):
          for col in range(9):
              if board[row][col] == 0:
                  for num in range(1,10):
                      if is_valid(board, row, col, num):
                          board[row][col] = num
                          solve(board)
                          board[row][col] = 0
  
                  return False
  
  print(np.matrix(board))
  
  solve(board)
  </code></pre>
  <hr />
  <p>The part that confuses me is:</p>
  <pre><code>if board[row][col] == 0:
      for num in range(1,10):
          if is_valid(board, row, col, num):
              board[row][col] = num
              solve(board)
              board[row][col] = 0
  
      return False
  </code></pre>
  <p>how is this part working? I know it will assign the number, to the current row and col
  THEN, run the solve() function again, so, when will the program run this:</p>
  <pre><code>board[row][col] = 0
  </code></pre>
  <p>because as I understand it, the code won't run unless there's a 0 already. Then the program will check if the number is valid or not.
  also if there's no num [1~9] that is valid, won't it return false and quit the function?</p>
  <p>talking about it makes my head spin, I know it's even hard to explain, I googled it.</p>
  <p>Edit:</p>
  <p>this is the board I'm dealing with:</p>
  <pre><code>board_1 = [
      [3, 0, 6, 5, 0, 8, 4, 0, 0],
      [5, 2, 0, 0, 0, 0, 0, 0, 0],
      [0, 8, 7, 0, 0, 0, 0, 3, 1],
      [0, 0, 3, 0, 1, 0, 0, 8, 0],
      [9, 0, 0, 8, 6, 3, 0, 0, 5],
      [0, 5, 0, 0, 9, 0, 6, 0, 0],
      [1, 3, 0, 0, 0, 0, 2, 5, 0],
      [0, 0, 0, 0, 0, 0, 0, 7, 4],
      [0, 0, 5, 2, 0, 6, 3, 0, 0]
      ]
  </code></pre>
  <p>Output:</p>
  <pre><code>[[3 1 6 5 7 8 4 9 2]
   [5 2 9 1 3 4 7 6 8]
   [4 8 7 6 2 9 5 3 1]
   [2 6 3 4 1 5 9 8 7]
   [9 7 4 8 6 3 1 2 5]
   [8 5 1 7 9 2 6 4 3]
   [1 3 8 9 4 7 2 5 6]
   [6 9 2 3 5 1 8 7 4]
   [7 4 5 2 8 6 3 1 9]]
  </code></pre>