Explicitly and without apology a marketing vehicle MaryMaryQuiteContrary

Friday Aug 13, 2004



we've got oh-so-much to be excited about today, people!

Friday Free Stuff* has a brand-spanking-new puzzler straight from the personal email account of Dr. Josh. (i just love it when he sends me personal email. have you bought his book yet?)

We've got a spectacular prize* this week...
picture of books

...my entire library of books about the Java platform. (all pristine condition, never even opened them.)

And most importantly, the XXVIII Olympiad officially begins tonight, bringing the games gloriously back to the country where they were born. ZHTO HELLAS!

picture of greek flag
(we've got a greek flag outside my house in celebration.)

So let's get straight to it. Because I've got to figure out where we're going to watch the opening ceremony as we have no TV. And my dad and mom (who live across the street) disconnected their cable when they took off for the summer. So I gotta work some angles....

Here's the puzzler:

The following loop looks like it should terminate immediately (after zero iterations):
   while (i != i)
;
But suppose you declare i like this:
   float i = 0.0/0.0;
If you try this and see what happens, you'll find out that it's an infinite loop! According to the spec 0.0/0.0 is evaluates to Float.NaN. NaN is an abbreviation for "not a number." The IEEE 754 specification says that NaN is not equal to itself (!), which explains the observed behavior. In similar fashion (but without resorting to floating point), provide declarations for i and j that turn each of the loops below into infinite loops:
  1.    while (j != j + 0)
    ;
  2.    while (k != 0)
    k >>>= k;
Please post your answers in the comments section of this blog entry. The person who most correctly, or in some other arbitrary way, answers the puzzler, wins* the prize*.

i love you too!

mary

* Friday Free Stuff is not a contest. It is me giving away something that I personally own to somebody that I choose. I pay for postage with stamps that I buy at the post office. But please, for my sake, if you live outside the US or Canada, please don't play this week. It would cost me a fortune to ship these books half-way round the world.

p.s. sorry about the quality of the pictures today. the digital camera eats up batteries like M&Ms. and i had no fresh ones to put in there. so i had to use the camera in my Java Powered mobile phone.