Pages, some stolen, some original

Thursday, March 5, 2015

War is Heck

Utopia Playing Cards
Working on another programming problem from codingame dot com today. This one is conceptually very simple, a simulation of the card game War. Being as it was such a simple problem, I had no trouble writing a program to do the simulation. No problem except that it didn't work. What was even worse was that it didn't fail completely, it passed some of the tests, but not others. Since the solution didn't require any intermediate results, I didn't bother to post any. It just ran until the end and then posted the results.
     But half the time the results were wrong, so obviously the program is doing something wrong, but without looking inside it's very hard to tell just what the problem is. I thought I would be clever and write a second, independent method, of solving the problem, and then programmatically compare the results after each step and so narrow down the location of the bug.
    Had more problems getting the second method working. To debug this second method I added a several statements to post intermediate results. The first few attempts produced no useful information, so I added more. The last one produced a clue, which pointed to the bug in the original solution. It was such a gross and obvious error that it's a wonder the program ran, much less passed any tests. Programming is sometimes very weird.

No comments:

Post a Comment