Explicitly and without apology a marketing vehicle MaryMaryQuiteContrary

Monday Aug 16, 2004

Ultimate Puzzler Challenge It's a MaryMaryQuiteContrary first! (well, not really but play along, will you?)

We've got a Friday Free Stuff tie! Christoph and Sue are finalists. They correctly answered last Friday's question. They get to take the Ultimate Puzzler Challenge, and battle it out for the specacular grand prize

picture of my books

(my entire library of books about the Java platform). Second runner up gets a leather Kenneth Cole PDA Holder. (sorry no picture handy; trust me, it's nice.)

But here at the MaryMaryQuiteContary everybody is a winner. Yes, you too can take the Ultimate Puzzler Challenge and get a piece of the Friday Free Stuff action. keep reading for details...

But first, last week's question:

In a recent blog entry I gave you two puzzlers from Dr. Josh and Dr. Neal. Each one consisted of a loop that looked like it did nothing, and you were supposed to come up with a declaration for the variable that caused it to spin forever, without using floating point. Here's the first loop:
 while (j != j + 0)
;
If it weren't for the restriction on using floating point, this would solve the puzzle:
 double j = Double.NaN;
Here's a solution that doesn't use floating point:
 String j = "Buy seventeen copies of Effective Java!";
This declaration turns the plus sign in the loop into the string concatenation operator. Then the int 0 is converted to the string "0" and appended to the blatant plug.

The plus sign is overloaded, and operator overloading can be very misleading: It looks like addition, but it's really string concatenation. It's all the more misleading because the variable is named j, which is generally used for ints. Good variable, method and class names are very important.

Now you're up-to-speed. You know what Christoph and Sue already knew. You're ready to take the Ultimate Puzzler Challenge. Please take out your Number 2 pencils...

The Ultimate Puzzler Challenge is this: without resorting to floating point, provide declarations for i and j that turn this loop below into an infinate loop (look carefully; it's not the same as Friday's):

 while (k != 0)
k >>>= 1;


Christoph, Sue: first one to post, wins.

Everybody else: post the right answer and I will send you FOC (Free of Charge) a full-color poster of the Java Technology Map. And while supplies last, I'll throw in a really nice ink pen too. See, there's something for everybody here at the MaryMaryQuiteContary blog. (or at least for the smart people ;-)

See you next time.

mary

p.s. i know you're not even going to believe this, but it's true. got email from Click and Hack. they signed it "kisses." putter, putter, my heart goes a-flutter.

p.p.s. this isn't a contest. i am giving away stuff that i pesonally own to people i choose. i pay for shipping with stamps that i buy with my own money from the post office.