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.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
|
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.