4 ms·
See http://www.joachimschipper.nl/posts/20100622/answer.txt http://www.joachimschipper.nl/posts/20100622/answer.txt. (Hidden behind a hyperlink to not spoil the
by JoachimSchipper 16y ago
See http://www.joachimschipper.nl/posts/20100622/answer.txt http://www.joachimschipper.nl/posts/20100622/answer.txt. (Hidden behind a hyperlink to not spoil the riddle.)
- RiderOfGiraffes 16y agoI think I disagree with you. The input you mention is correctly handled by the routine you mention, and is tested correctly. Certainly there is a bug other than the one you think you've found, and I don't think the circumstances you mention demonstrate a bug at all. I would certainly be interested in seeing a more detailed analysis.
- JoachimSchipper 16y agoYou're right, that answer isn't correct. I still think that particular input should be tested, though (you say it is - did you leave out that part of your testing program? It should be possible to construct a program that fails on such inputs.) I don't think I've found a real "bug" yet. You include, but don't use, stdlib.h; you exit with status 0, even on error; but these are nitpicks, not what you mean. I'll think a bit more.
- RiderOfGiraffes 16y agoI tested that case when you mentioned it. All routines submitted pass it correctly, so I haven't worried about it too much. To do so would be to stray too far from the original intention. I think it's hard to write a natural looking routine that fails that test. I return 0 in all cases because my test succeeds, even if the routine it's testing fails. It's up to my shell to decide what to do about that error. As it stands it reports the error, but it has succeeded in doing so, so it hasn't failed. But that's not the point, as you say. And the real bug is still there.
- JoachimSchipper 16y agoWell, I'm stumped. I can think of some other "cosmetic" issues and some things you fail to test (e.g. that the function is in-place, runs in O(strlen(z_terminated)) and does not access memory beyond z_terminated[strlen(z_terminated)]), but that's it. Besides, as you mention, such issues can usually be found just by looking at the function. Will you give out the answer at some point?
- RiderOfGiraffes 16y agoYes - in the next part of the analysis.