drafted C++ implementation of Cash-Karp