First let's remind you of the question, provided to me by 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.)
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;
}
The answer is: The multiplicative inverse of val mod 232 (i.e. the unique int i such that val * i == 1). It turns out that mysteryFunction is doing Newton iteration. The details can be found in this great book: http://www.amazon.com/exec/obidos/tg/detail/-/0201914654 .
And now let's talk about our winners!
But before we do that, I'd like to award our special Reserve Grand Champion Award to Klaasjan Tukker, who submitted the following stellar answer. True, it's technically wrong. But it made Click and Hack laugh. And Klaasjan knows Onno so that also scored some points with the judge (me).
| Subject: | mysteryFunction solved !! |
|---|---|
| Date: | Sat, 19 Jun 2004 09:51:32 +0200 |
| From: | Klaasjan Tukker - Dutch Java User Group, NLJUG <CENSORED BY MARY> |
| To: | 'Mary Smaragdis' <first.last@Sun.COM> |
Hi Mary,
I think Click and Hack are genius !! They found a formula to profile the
track of the upcoming "Tour de France" !!
See:
* www.letour.fr
And compare the attached results of the permutations presented in the graph
with the track-profile on:
http://www.letour.fr/2004/presentationfr/profil17.html
Cycling in the Netherlands is boring; it is _so_ flat. You can ask Onno
Kluyt of JCP to verify; he is a very enthousiast cyclist:
http://jroller.com/page/OnnoKluyt/20040618
Met vriendelijk groet,
Klaasjan Tukker
Voorzitter NL-JUG, Nederlands Java User Group
Chairman NL-JUG, Dutch Java User Group
CENSORED BY MARY@nljug.org
www.nljug.org
Now, let's get back to our three Grand Prize Winners...
(please hum your favorite national anthem and imagine the raising of the flag of your choice.)
1. Ron Yang posted his answer in the comments section of the blog. He's close enough for government work so he wins the prize. (I didn't get a chance to "talk" to Ron so I don't have the usual plugs you'll see below. Stay tuned on that front.
2. Luke Hutteman also submitted the correct answer. Luke, by the way, is the author of the SharpReader RSS Aggregator. And the only reason this aggregator (which is written in C#/.NOT) is getting a mention in this precious real estate is because Luke is an honest, good guy. So just back off on the reply button, people. Luke's with me.
3. Ryan Ripley is our third and final grand prize winner! Look at him, all thoughtful and cool in his baseball cap...

So those are are big winners. I would like to congratulate you for being so smart, gentlemen. This was a hard one. (I'm told; not that i have any personal understanding of any of this whatsoever.) Before we conclude, I would like to take a moment to recognize some other stellar entries...
Mayank Sharma sent in a great submission. I didn't understand a word of that one either. But Mayank knows Danese Cooper so he gets special honorable mention for that -- if for no other reason.
And Sun employee Dan Lacher gets a special honorable mention...He made my day by submitting this -- the world's first Java code with my name in it! (!!!!)
public class Mary1 {
private int val;
public void setVal(int v) {
val = v;
}
public Mary1 () {
val = 0;
}
public Mary1 (int v) {
val = v;
}
static int calcT (int val) {
int t = val;
t *= 2 - val * t;
t *= 2 - val * t;
t *= 2 - val * t;
t *= 2 - val * t;
t *= 2 - val * t;
System.out.println("value: " + val + " t: " + t);
return t;
}
}
#file2 Mary1Test.java
public class Mary1Test {
public static void main (String args[]) {
Mary1 myMary1 = new Mary1();
for (int i = 1; i < 256; i+=2) {
myMary1.calcT(i);
}
}
}
# the results
value: 1 t: 1
value: 3 t: -1431655765
value: 5 t: -858993459
value: 7 t: -1227133513
<snip>
value: 249 t: 241484105
value: 251 t: -1711142349
value: 253 t: -424403883
value: 255 t: -16843009
One final note: special extra thanks and a big kiss go to Luke and Ryan who helped me by serving as my honorary judges. (I didn't want to bother Click and Hack because I bet they are super busy getting ready for their two JavaOne sessions: One, Two.)
And that concludes this week's Friday Free Stuff.
whew.
OK, Good news and bad news.
Good news: JavaOne is going to yield a cornucopia of Free Stuff that we're going to be giving away in the coming weeks and months.
Bad news: It's literally going to be weeks and months until we play Friday Free Stuff again. We're not playing this week or next because frankly I'm too busy. And you'll recall I'm on vacation for the month of July. So we're not going to play Friday Free Stuff again until August. sorry... i promise it will be worth the wait....
mary

Posted by Dan Lacher on June 25, 2004 at 05:52 AM PDT #
Posted by Mary on June 25, 2004 at 07:17 AM PDT #