Recently I have been trying to get some experience at solving some algorithm intensive problems by taking part in online programming contests.
The problems are no doubt very interesting and there is lot to learn from them. I have myself learned a lot about new algorithms and different ways of problem solving.
But I have some critical observations about these contests as well. In one of the recent problems which I was solving, I managed to get the correct implementation, but it used to all ways exceed the execution time limit. My implementation was not very unoptimized, it was a very simple implementation of the solution and very readable. I tried multiple iterations but did not manage to satisfy the execution time limit.
Out of curiosity I looked at some of the correct submissions, and found that all of them had implemented a very specific solution, which involved inlining lot of operations, and resulted in very unreadable code. I felt that the tester of the solution had reverse engineered using this solution and then set the time limits.
This I feel is a very wrong way of writing programs. Any experienced software engineer will tell you that the best program is the one which produces the right result and does so keeping the code simple. Simple enough so that people other than the author can also understand the code. This is also mentioned in Eric Raymond’s 17 Unix Rules, Rule of Clarity.