Today I finished debugging a problem called “ro” that was proposed at an earlier round of .Campion. The screenshot shows the only change in the source code that, applied, would have brought me 100 points instead of 20.
- If anything can go wrong, it will.
- If anything just cannot go wrong, it will anyway.
Now, more seriously:
- Always, and I mean always make a backtracking, fail-safe solution and test the results for some small test case.
- If you’re getting lost in that ugly 500+ line program, better start from scratch than trying to patch it.
For the reference, here’s the quick’n’dirty bash script I used to test my solution after correcting it:
for i in `seq 1 20`; do echo “test $i” && cp $i-ro.in ro.in && time ./minchange.e && head -n 1 ro.out > ro.out1 && head -n 1 $i-ro.ok > $i-ro.ok1 && diff ro.out1 $i-ro.ok1 && rm ro.out1 $i-ro.ok1 || break; done
minchange.e is the program executable name, located in the current directory.