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.
use v6; my %ball = map { $_ => 1; } 1..12; Modify_Ball( %ball ); say ~Find_Odd_Ball( %ball ); say %ball.perl; sub Find_Odd_Ball (%ball) { my $r_1 = ([+] %ball{1..4}) <=> ([+] %ball{5..8}); given $r_1 { when 0 { my $r_2 = ([+] %ball{9,10}) <=> ([+] %ball{1,11}); given $r_2 { when 0 { return (12, %ball{12} <=> %ball{1}) } default { my $r_3 = %ball{9} <=> %ball{10}; given $r_3 { when 0 { return (11, $r_2 * -1) } default { return $r_2 == $r_3 ?? (9, $r_3) :: +(10, $r_3 * -1) } } } } } default { my $r_2 = ([+] %ball{1,2,5}) <=> ([+] %ball{3,6,10}); if ! $r_2 { my $r_3 = %ball{7} <=> %ball{8}; given $r_3 { when 0 { return (4, $r_1) } default { return $r_1 == $r_3 ?? (8, $r_3 * -1) :: + (7, $r_3) } } } return %ball{3} == %ball{10} ?? (5, $r_2) :: (3, $r_1) if +$r_1 ne $r_2; my $r_3 = %ball{1} <=> %ball{2}; given $r_3 { when 0 { return (6, $r_2 * -1) } default { return $r_2 == $r_3 ?? (1, $r_2) :: (2, $r_2 +) } } } } } sub Modify_Ball( %ball is rw ) returns Void { my $num = int( rand 12 ) + 1; my $adj = .1 * (int( rand 2 ) ?? 1 :: -1); %ball{$num} += $adj; }

Cheers - L~R


In reply to Re^2: Odd Ball Challenge by Limbic~Region
in thread Odd Ball Challenge by Limbic~Region

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.