> When dealing with dataset 4, my program skips the > last piece in the input (R), since it has a coordinate > of 5, which is outside the board. The program then > runs using the other pieces. However, none of them is > an astronaut! The program runs correctly, and quickly > reports that there is no solution. However, I can > easily make it "not waste" any effort in even looking > for one, by first checking that there is an astronaut > in the input file. On the other hand, doing this adds > a step to the program in all the standard cases when > an astronaut is given. Which option do you think is > better?
I think you definitely have to check for the presence of an astronaut. You can not just assume that the input data will be okay. > In general, in the "professional world", what > would you do in a similar situation - when you could > save some time by not checking everything as long as > the output is correct (ie the issue is dealt with > while running the program), but at the same time you > can save time in the rare cases when you know a priori > that there is no solution? If you are a serious programmer you check and double-check to make sure that your input data is not corrupt. In this case the check only has to be done once, at start-up, so this cannot even be considered to be efficiency issue. (But even if you had lots of data you would have to check.) Some of the security bugs (array boundary thrashing) that Dr. Parker loves so much, may also have been the result of clever programming: "We don't need to check this, because we KNOW this index will never get greater than the array bounds." The only viable philosophy for a programmer is Pyrrhonism. > Does the question even make > sense to you - it's really hard for me to put it in > words! Makes perfect sense to me, and is a good question to ask. Hans
