input: Write a function to optimize an equation by combining like terms. If the input equation is in the form of 'x + x + y + y + y', the function should return an optimized equation in the form 'x^2 + y^3'.
  
  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 + a + b + b')=='a^3 + b^2'
  assert optimize_equation('c + c + c')=='c^3'
  assert optimize_equation('d + e')=='d^1 + e^1'
  assert optimize_equation('')==''
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]