def __str__(self):
    """It can be done smarter not to print redundant parentheses,
           but that is out of the scope of this problem.
        """
if self.op:
    return '({0}{1}{2})'.format(self.left, self.op, self.right)
else:
    return '{0}'.format(self.value)
Generate equation with the result value closest to the requested one, have speed problems