code for our heuristic partition