Salutations. Dijkstra wrote that even a few lines of seemingly simple code could be hopelessly ambiguous. In at least one work, which I can't find now to save my life, he gave a little example program to demonstrate this ambiguity. Can anybody point me to a paper of his where he includes one of these examples?
http://www.cs.ucsb.edu/~pconrad/cs40/08S/notes/ has nice coverage; search for "halting problem"
There are several forms of the essential halting contradiction.
Does the "whistler" whistle zero, once or an infinite number of times?
Are you sure that the paper was by Dijkstra? Reflections on Trusting Trust by Ken Thompson sounds like it could be what you were thinking of. It demonstrates how absolutely simple, straightforward, and correct programs could wind up doing something absolutely unexpected that isn't visible at all in the source. Even if it isn't what you were thinking of, it is a worthwhile paper to read.
Going a different direction, if you want excellent examples of short programs with surprising behavior, the underhanded C contest is great. For example look at the 2008 winner. The challenge was to write a command line program to blank out part of a picture, in such a way that the picture visually was blanked out perfectly, but the file retains some information about the redacted part of the image. AND in such a way that your code could pass code review. (You could choose the format that the picture is stored in.)