13 hours ago
Saturday, April 26, 2014
I'm #484! -or- Skynet Part 2
The coding contest is over. It closed at one this afternoon while I was taking a nap, or I was at the store, I'm not sure which. There were two problems to solve. I got the first one sort of done, it passed the first three tests, but then started timing out (failed to run to completion in the alloted time, however many seconds that was) on the 4th.
I could say I wasn't doing anything that should cause that kind of problem, but that sounds a lot like a baseball player saying "the sun got in my eyes" when he drops the fly ball that was going right to him.
'C' is a low level language, as programming languages go. It is compiled, which means you feed your source code (the text file which contains the program you have written) to the compiler, which is another computer program that turns your source code into machine code. If you look at the assembly language version of the compiled program, you will see that for every statement you wrote in your source code, the compiler has produced a specific series of machine language instructions. (Assembly language is basically machine code, it just substitutes cute little acronyms for unprintable numbers). So a program written in 'C' should be lightning fast, especially compared to some of these new fangled languages that attempt to interpret every wave of your hand as something meaningful.
I noticed however, that things might not quite be like this. At some point when you are writing a 'C' program, you decide it's time to test it, which means feeding it to a compiler, which means, if you are like me, you get back a boatload of errors complaining about unknown (misspelled) variables, missing semi-colons, and a raft of incorrect punctuation. So you edit your source code and fix the errors and try again.
Now this is where the PC has it all over the main frame. When I started in the business (sorry, time for a trip down memory lane) you wrote your program on punched cards, one line to a card, carried your box of cards to the super-secret I/O room, turned your cards into the operator, and then waited for your program to run, the output to be printed, the operator to tear off the printout from the printer and dump it in the delivery folder. Then you got to drag the printout around until you found a clear space on a table where you could spread it out and try and decipher whatever cryptic message the compiler has deigned to bestow upon your work. Now with a PC, you press the go button and quicker than you can say Jack-Sprat, the compiler is done and it has volumes to tell you about your incompetence, your heritage and your personal shortcomings.
All that is a long winded way to say that there are compile time errors and there are run-time errors. Even if your program compiles error-free, it still has to run, and this is where the real problems make themselves known, because here you are at the mercy of the OS (Operating System), and the OS doesn't care who you are, or who your daddy is, or much of anything, as long as you mind your P's and Q's. Step out line just once, and boom! Down comes the smack, your program gets axed and all you get is some cryptic message like "segmentation fault" at PC nine zillion and some random bunch of digits.
However, in this contest, methinks they weren't actually compiling my code even though I was writing in 'C'. I think they were using some kind of interpreter because sometimes I would get compile-time-type errors and sometimes I would get run-time-type errors, and sometimes the compile-time-type errors would show up after the run-time errors, which is a little hard to do, well, unless you are the wizard and you are controlling what goes on behind the curtain, which in this case the contest perpetrators surely are.
So anyway, even though I fell asleep before I completed this project, I had done enough that they gave me 25% credit and 484th place in the contest.
I am going to have to go back and look at some of the winners when they are released this evening. Maybe this old dog can learn some new tricks. Not likely, but at least I can claim to be trying.
More info about the contest here.