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?

use Test::More tests => 24; use warnings; for( 1 .. 12 ) { %ball = map { $_ => 1; } 1..12; for $d ( -1, +1 ) { $ball{$_} = 1 + $d * 0.1; is_deeply( [$_, $d], [Find_Odd_Ball()], "($_, $d)" ); } } sub Find_Odd_Ball { my $result_1 = $ball{1} + $ball{2} + $ball{3} + $ball{4} <=> $ball +{5} + $ball{6} + $ball{7} + $ball{8}; if( $result_1 == 0 ) { my $result_2 = $ball{9} + $ball{10} <=> $ball{1} + $ball{11}; if( $result_2 == 0 ) { return (12, $ball{12} <=> $ball{1}); } else { my $result_3 = $ball{9} <=> $ball{10}; if( $result_3 == -1 ) { return (9, $result_2 == $result_3 ? -1 : 1 ); } elsif ($result_3 == 0 ) { return (11, $result_2 * -1); } else { return (10, $result_2 == $result_3 ? 1 : -1 ); } } } else { my $result_2 = $ball{1} + $ball{2} + $ball{5} <=> $ball{3} + $ +ball{6} + $ball{10}; if( $result_2 == -1 ) { my $result_3 = $ball{1} <=> $ball{2}; if( $result_3 == -1 ) { return (1, $result_1); } elsif( $result_3 == 0 ) { return (6, $result_1 * -1); } else { return (2, $result_1 * -1); } } elsif( $result_2 == 0 ) { my $result_3 = $ball{7} <=> $ball{8}; if( $result_3 == -1 ) { return (8, $result_1 * -1); } elsif( $result_3 == 0 ) { return (4, $result_1); } else { return (7, $result_1 * -1); } } else { return $ball{3} == $ball{10} ? (5, $result_1 * -1) : (3, $ +result_1); } } }

In reply to Re^3: Odd Ball Challenge by kaif
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.