Explicitly and without apology a marketing vehicle MaryMaryQuiteContrary

Thursday Jun 24, 2004

I have good evidence that you guys -- the readers that I slave for -- are very smart.

But we still have no winner on last week's Friday Free Stuff. What's that all about?

Have I "Stumped the Chump?" (good writers borrow; great writers steal.)

This is the last call...

What does the following function compute?

    // Assumes val is odd
   static int mysteryFunction(int val) {
       int t = val;
       t *= 2 - val*t;
       t *= 2 - val*t;
       t *= 2 - val*t;
       t *= 2 - val*t;
       return t;
   }

I got the question from "Click and Hack, the type-it brothers" .....

...aka Dr. Joshua Bloch and Dr. Neal Gafter. (Did you know they have two JavaOne sessions: One, Two.)

The prize (Duke dolls) ...

... courtesy of Mary.

Friday Free Stuff is not a contest. Mary is giving away something she personally owns to somebody she picks. She pays for shipping. Sun employees can play but can't "win."

mary

Comments:

I will claim it... I had the code typed up w/ you in the title :) Just kidding, I know the rules and someone will win them someday on a different question.

Posted by dl on June 24, 2004 at 09:39 AM PDT #

I think it calculates 1/val If you print the results as binary, it looks like binary fractions. Also, f(f(x)) = x. So how many non-trivial functions are themselves their inverse? So my guess is f(x) = 1/x. :)

Posted by Ron Yang on June 24, 2004 at 10:40 AM PDT #

The code returns the multiplicative inverse of val mod 2^32. It is straight from the comments in the MutableBigInteger class... --Ryan

Posted by Ryan Ripley on June 24, 2004 at 11:02 AM PDT #

The code returns the multiplicative inverse of val mod 2^32. It is straight from the comments in the MutableBigInteger class... --Ryan

Posted by Ryan Ripley on June 24, 2004 at 11:05 AM PDT #

Post a Comment:
Comments are closed for this entry.