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 simplified string equation as output. The equation is given in the form of terms separated by '+', where each term is a variable followed by a space and then its coefficient. If the coefficient is 1, it should be omitted in the output.
  
  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:
          if count > 1:
              new_equation += (var + '^' + str(count)) + ' + '
          else:
              new_equation += var + ' + '
      return new_equation[:-3]
  
  equation = 'x + x + y + y + y'
  
  print(optimize_equation(equation))
  
  assert optimize_equation('x + x + y + y + y') == 'x^2 + y^3'
  assert optimize_equation('a + a + b + b + b + c') == 'a^2 + b^3 + c'
  assert optimize_equation('x + y + z') == 'x + y + z'
  assert optimize_equation('a + a + a + b') == 'a^3 + b'
output: def optimize_equation(equation):
      terms = equation.split(' + ')
      count_dict = {}
      for term in terms:
          var, count = term.split(' ')
          count = int(count)
          if var in count_dict:
              count_dict[var] += count
          else:
              count_dict[var] = count
      
      result = []
      for var, count in count_dict.items():
          if count > 1:
              result.append(f"{var}^{count}")
          else:
              result.append(var)
      
      return ' + '.join(result)