input: Write a function to generate a spiral matrix.
  assert generate_spiral_matrix(3, 3) == [1, 2, 3, 6, 9, 8, 7, 4, 5]
  assert generate_spiral_matrix(4, 4) == [1, 2, 3, 4, 8, 12, 16, 15, 14, 13, 9, 5, 6, 7, 11, 10]
  assert generate_spiral_matrix(2, 2) == [1, 2, 4, 3]
output: def generate_spiral_matrix(rows, cols):
      def spiral_coords(r, c):
          for i in range(c): yield 0, i
          for i in range(1, r): yield i, c - 1
          if r > 1:
              for i in range(c - 2, -1, -1): yield r - 1, i
          if c > 1:
              for i in range(r - 2, 0, -1): yield i, 0
  
      matrix = [[0] * cols for _ in range(rows)]
      val = 1
      r1, r2 = 0, rows - 1
      c1, c2 = 0, cols - 1
      
      while r1 <= r2 and c1 <= c2:
          for r, c in spiral_coords(r2 - r1 + 1, c2 - c1 + 1):
              matrix[r + r1][c + c1] = val
              val += 1
          r1, r2 = r1 + 1, r2 - 1
          c1, c2 = c1 + 1, c2 - 1
  
      return [matrix[r][c] for r in range(rows) for c in range(cols)]