input: Write a function to optimize an equation by combining like terms. The input is a string representing an equation with repeated terms, and the output is a string representing the optimized equation.
  def optimize_equation(equation):
      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]
  
  assert optimize_equation('x + x + y + y + y')=='x^2 + y^3'
  assert optimize_equation('a + a + b + b + b + c + c + c + c')=='a^2 + b^3 + c^4'
  assert optimize_equation('d + d + d + d + d + d')=='d^6'
  assert optimize_equation('')==''
  assert optimize_equation('e + e + f + f + f')=='e^2 + f^3'
output: def optimize_equation(equation):
      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]