# patchprog2520.py -- wang_prog.cpp = wang_ties.cpp + a progress line to stderr after every completed depth-0/depth-1 branch import io t = io.open('wang_ties.cpp', encoding='utf-8').read() a = " for (int i = 1; i < p; ++i)\n if (i != skip) {" assert t.count(a) == 1 t = t.replace(a, " for (int i = 1; i < p; ++i) { if (i != skip) {") b = " }\n }\n else {" assert t.count(b) == 1 progress = ' } if (k <= 1) { fprintf(stderr, "progress depth %d branch %d/%d elapsed %.1f s' + '\\' + 'n", k, i, p, (double)(clock()-T0)/CLOCKS_PER_SEC); } }\n }\n else {' t = t.replace(b, progress) t = "#include \n#include \nstatic clock_t T0;\n" + t c = " TARGETM = (target - 5) / 6;" assert t.count(c) == 1 t = t.replace(c, " T0 = clock();\n TARGETM = (target - 5) / 6;") io.open('wang_prog.cpp', 'w', encoding='utf-8', newline='\n').write(t) line = [l for l in t.splitlines() if 'progress depth' in l][0] print('ok; progress line ends with:', repr(line[-60:]))