24-point algorithm (C++ implementation)