in reply to Odd Ball Challenge

In order to understand the challenge, I translated the code in your OP (I lack Perl 6) to a scripting language which happens to support given, when, and default. I had a hell of a time getting it to work - then I noticed this little detail in the OP which I had originally misread:

I have included a currently non-working Perl6 solution below.
I say currently because I suspect the problem is with Pugs and not with the code.

So, maybe my time was not wasted.. perhaps if we compare our results, we can determine whether or not it's your algorithm that is to blame.

My translation of your algorithm returned correct results in most cases, but failed the following:

actual detected ball 2 light ball 2 heavy ball 5 light ball 6 light ball 6 light ball 5 light ball 7 light ball 8 light ball 8 light ball 7 light ball 1 heavy ball 5 light ball 2 heavy ball 5 light ball 3 heavy ball 6 light ball 9 heavy ball 10 heavy ball 10 heavy ball 9 heavy
If you're getting the same failures, perhaps the problem is in your algorithm.

Replies are listed 'Best First'.
Re^2: Odd Ball Challenge
by Limbic~Region (Chancellor) on Jun 24, 2005 at 23:13 UTC
    djohnston,
    The code won't even run at all currently under Pugs. If it is consistently giving the wrong answers then it is probably just a mapping issue. In order to verify, you would need to remove the randomness and force each ball to be heavy and then light in succession. The solution itself isn't the challenge though. The challenge is to write code that generates a solution.

    Cheers - L~R

      I'm having trouble understanding how it even compiles. Isn't

      when -1 { return (9, $result_2 == $result_3 ? +? -1 :: 1 }

      a syntax error (mismatched parentheses)? If so, there are a few lines like that. Also, one line refers to

      when 0 { return (12, %ball{12} <=> %ball{0}) }

      where 0 should probably be 1. Finally, I confirm all of djohnston's results by translation to Perl 5 (for example, just imagine ball 1 is heavier and run through the code mentally --- it indeed says something about either ball 3 or 5). Pardon the ugly code; the Perl 6 is certainly prettier. But as Limbic~Region says, solving the riddle isn't the challenge, right?

        kaif,
        I'm having trouble understanding how it even compiles.

        As I stated - it doesn't compile or run. The typo you pointed out isn't the problem though. There are several bugs I uncovered in testing this code that won't even let a very minimal implementation run.

        Thanks for the code - I will investigate further when I get a chance.

        Cheers - L~R

Re^2: Odd Ball Challenge
by Limbic~Region (Chancellor) on Jun 30, 2005 at 17:52 UTC
    djohnston,
    There were a few missing parens in my code, a handful of bugs in Pugs, and an incorrect translation of the puzzle solution logic to code. The following is working p6 code that produces correct results.

    Cheers - L~R