input: Write a function to optimize an equation by combining the same terms. If the equation is empty, return an empty string.
  def optimize_equation(equation):
      if not equation:
          return ""
      variables = []
      for term in equation.split('+'):
          var, count = term.strip().split(' ')
          variables.append((var, int(count)))
  
      new_equation = ""
      for var, count in variables:
          new_equation += (var + '^' + str(count)) + ' + '
      return new_equation[:-3]
  
  assert optimize_equation('x + x + y + y + y') == 'x^2 + y^3'
  assert optimize_equation('a + a') == 'a^2'
  assert optimize_equation('b + b + b + c + c') == 'b^3 + c^2'
  assert optimize_equation('') == ''
  assert optimize_equation('d + d + d + d') == 'd^4'
output: def optimize_equation(equation):
      if not equation:
          return ""
      variables = {}
      for term in equation.split('+'):
          var = term.strip()
          if var in variables:
              variables[var] += 1
          else:
              variables[var] = 1
  
      new_equation = ""
      for var, count in variables.items():
          new_equation += (var + '^' + str(count)) + ' + '
      return new_equation[:-3]