input: Write a function to optimize an equation by combining like terms. The function should take a string representing the equation as input and return a string representing the optimized equation.
  
  def optimize_equation(equation):
      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 + b + b')=='a^3 + b^2'
  assert optimize_equation('c + c + c + c + c + d')=='c^5 + d^1'
  assert optimize_equation('e + e + f + g + g')=='e^2 + f^1 + g^2'
  assert optimize_equation('h + i')=='h^1 + i^1'
output: def optimize_equation(equation):
      terms = equation.split(' + ')
      counts = {}
      for term in terms:
          var = term.strip()
          if var in counts:
              counts[var] += 1
          else:
              counts[var] = 1
      
      optimized_terms = []
      for var, count in counts.items():
          optimized_terms.append(f"{var}^{count}")
      
      return ' + '.join(optimized_terms)