First implementation of solve(). Runs ~6000 iterations, slow (5+ minutes)