• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Challenge!

 
Author and "Sun God"
Posts: 185
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Someone asked if the puzzles in the book are real or "trivia." They are very real! Most of them come from bug reports, where some programmer thought the platform was broken when it was doing exactly what it was specified to do.

These things can bite you. Heck, they can bite us. In fact, they did bite us. We fell into one of the traps in writing the solution to another. I won't tell you which one (for now). I will tell you that the trap is discussed in one of the Looper puzzles (Puzzles 28 to 33), and that the answer containing the broken code is in Chapter 7 (Library Puzzlers). If anyone can find the broken code in the book before the week is out, we will send you autographed copies of "Effective Java" and "Java Puzzlers." (This is in addition to the four copies of "Java Puzzlers" that Addison is awarding.)

Have at it,

Click and Hack, the Fallible Type-it Brothers

P.S. The first correct response wins the prize.
[ August 09, 2005: Message edited by: Joshua Bloch ]
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just sent Josh a private message with what I think is the answer. (Josh, you can find it here in case you don't receive the e-mail notification.) I won't post it publicly yet so others can continue the fun of searching for it. Also I may be wrong, as I haven't yet verified carefully.
 
Joshua Bloch
Author and "Sun God"
Posts: 185
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Folks,

Jim is our winner, but I won't post the answer yet. It will be going up on the errata page for the book later this week. Congrats, Jim, that was fast!

Click and Hack the Type-it Brothers
 
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Unfortunately, the book hasn't yet arrived in Australia. I ordered it from the US the day it became available - still waiting...
 
Joshua Bloch
Author and "Sun God"
Posts: 185
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tony,

Sorry. This challenge wasn't completely fair. Perhaps we'll post another challenge before the week is out.

Click and Hack
 
Joshua Bloch
Author and "Sun God"
Posts: 185
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Folks,

We have decided to make a second pair of books available to the second person who finds the bug!

Click and Hack, the Type-it Brothers
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dr. Bloch

The broken code is probably the hash code method in the puzzle "What's in a name?". From the idea you suggested on puzzle "A Big Delight in Every Bite", we may do lazy initialization to fix it. So the hash code method may look like this.

private volatile int goodPuzzle = 0;

public int hashCode()
{
if (goodPuzzle == 0)
{
goodPuzzle = 37*first.hasCode() + last.hashCode();
}
return goodPuzzle;
}

Please give us the sneak peak of the answer after there is a winner. We will find detail in the errata later. It is fun thinking about it. Thank you.

Worachat
 
Ranch Hand
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Joshua,

Can we read this book online. So we can find out the broken code. Because most of us don't have book yet.
 
Joshua Bloch
Author and "Sun God"
Posts: 185
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rathi,

Well, at least you can read the sample chapter (http://www.javapuzzlers.com/java-puzzlers-sampler.pdf). It's not enough to solve this particular challenge, but it will give you a good idea what the book is all about.

Regards,

Josh and Neal

Originally posted by rathi ji:
Hi Joshua,

Can we read this book online. So we can find out the broken code. Because most of us don't have book yet.

 
Jim Yingst
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[Worachat]:The broken code is probably the hash code method in the puzzle "What's in a name?".

No, unfortunately the bug referred to here is not part of "What's in a name?" or any other part of the freely-available sample chapter. It is only in Chapter 7 of the actual book, "Java Puzzlers". If you live in a country where the book is available a local bookstore, you may be able to go there and search through chapter 7 until you find the problem (that's what I did; I hadn't bought this book yet). If the book is unavailable - I guess there's not much you can do. Please remember that at this point, it's probably the publisher who controls which portions of the book are freely available, and which are not. There have been a few cases of books being made freely available online and still having reasonably good sales - "Thinking in Java" comes to mind - but most publishers still aren't using this paradigm. Most will offer some sort of free sample - e.g. the sample chapter[/url] - but after that, the publisher (and in most cases, the author(s)) is hoping you'll actually buy the book. Which is a long way of saying that it would certainly be nice if the source materials for the challenge were free and/or available in all countries - but it's quite possibly beyond Josh and Neal's ability to change at this point.

Now, if it somehow is possible to have a challenge where the source materials are equally available to everyone, that would certainly bee cool. Maybe with one of the puzzlers that didn't make it into the book, assuming
Josh and Neal still have extra copies? But if it's not possible, I hope everyone will understand.
 
Joshua Bloch
Author and "Sun God"
Posts: 185
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Folks,

Sit tight. We are trying to think of another challenge.

Josh and Neal
 
Worachat Maneein
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sheriff Jim,

Thanks for the advice. Maybe once in a while the ranch pops some quizzes to let people think which will help people learn about subject. It's a great fun to learn.

Worachat
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We have a whole forum for puzzlers. It's called "Programming Diversions"
 
blacksmith
Posts: 979
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'll give it a shot, I think the broken code lies in
Puzzle 64.

'The mod squad' the proposed method 'private static
int mod(int i, int modulus)' does not work
correctly for border cases like Integer.MIN_VALUE.
The solution of Puzzle 33 Looper meets the Wolfman
it warns of these corner cases.

Cheers,

Gian
[ August 10, 2005: Message edited by: Gian Franco Casula ]
 
Joshua Bloch
Author and "Sun God"
Posts: 185
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Gian,

Sorry, but this is not the answer. Our solution to that problem (which I won't include inline so as not to give away the puzzle) does work for Integer.MIN_VALUE (and all other int values).

Regards,

Click and Hack (still the Type-it Brothers)

Originally posted by Gian Franco Casula:
I'll give it a shot, I think the broken code lies in
Puzzle 64.

'The mod squad' the proposed method 'private static
int mod(int i, int modulus)' does not work
correctly for border cases like Integer.MIN_VALUE.
The solution of Puzzle 33 Looper meets the Wolfman
it warns of these corner cases.

Cheers,

Gian

[ August 10, 2005: Message edited by: Gian Franco Casula ]

 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is a tough challenge, I'm still patiently working through Chapter 6. Learnt a ton of things on the way. Great book!
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By the way, in the Safari version of the book they have the question and solution on the same page, not as the hardcopy is printed. That's a bit of a spoiler that should be corrected.

Oh yes. Elvis is missing an import.
 
Gian Franco
blacksmith
Posts: 979
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I hope I found it now, in any case in the process I learned a lot

The problem lies in Puzzle 65 'A strange saga...'. The "not clever"
compare method, proposed at the end of the solution, is incorrect,
because it uses the equality operator (i.e. ==) to compare the
two parameters of the method (i.e. i2 == i1)

Since, as Puzzle 32 Curse of looper states, for boxed numeric types:
Numerical operators perform value comparisons, while equality operators
perform reference identity comparisons, the equality operator in Puzzle 65
is incorrect.

Sounds good to me, but bare in mind I haven't slept a lot since
the challenge started,

Cheers,

Gian
[ August 11, 2005: Message edited by: Gian Franco Casula ]
 
Joshua Bloch
Author and "Sun God"
Posts: 185
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Gian,

Congratulations! You are our second (and final) winner! That's exactly right. Now get some sleep.

Way to go,

Click and Hack, the Type-it Brothers

Originally posted by Gian Franco Casula:
I hope I found it now, in any case in the process I learned a lot

The problem lies in Puzzle 65 'A strange saga...'. The "not clever"
compare method is incorrect because it uses the equality operator
(i.e. ==) to compare (i.e. i2 == i1)

Since, as Puzzle 32 Curse of looper states, for boxed numeric types: Numerical operators perform value comparisons, while equality operators perform reference identity comparisons, the equality operator in Puzzle 65 is incorrect.

Sounds good to me, but bare in mind I haven't slept a lot since
the challenge started,

Cheers,

Gian

[ August 11, 2005: Message edited by: Gian Franco Casula ]

 
Gian Franco
blacksmith
Posts: 979
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wooooooooooooooooooow,

I'm stunned by such a quick reply.

Thanks Josh, I guess I'm not the only one not sleeping.



Cheers,

Gian
 
Joshua Bloch
Author and "Sun God"
Posts: 185
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Barry,

Thanks for the kind words! Also thanks for the heads-up regarding the Safari version. We will tell our editor and see if they can correct this pronto! As you might have guessed, we worked very, very hard to get the layout to workout properly. Now we know why most puzzle books don't alternate puzzles and solutions

By the way, that's why the book has all of those cool illusions in it. Alternating puzzles and solutions necessitates a certain amount of whitespace, but Click and Hack wanted to give you your money's worth So we filled the whitespace with illusions. We learned an awful lot about illusions in the process.

Regards,


Click and Hack

P.S. Regarding the import, I think we left it out intentionally to make the program fit on the page. It was a compromise. Recall that I (Josh) always left out imports of java.util in "Effective Java."
 
Gian Franco
blacksmith
Posts: 979
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Joshua,

I've sent my mail details to
your mail address.

Thanks again!

Cheers,

Gian
reply
    Bookmark Topic Watch Topic
  • New Topic