Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Odd Ball Challenge

by ej8000 (Initiate)
on Aug 01, 2011 at 22:18 UTC ( [id://917931]=note: print w/replies, xml ) Need Help??


in reply to Odd Ball Challenge

hi all, I have a working solution in perl 5.14

use v5.10; %ball=map{$_ =>1}1..12; Modify_Ball( %ball ); say Find_Odd_Ball( %ball ); sub Find_Odd_Ball (%ball) { my $result_1 = ((eval join '+', @ball{1..4}) <=> (eval join '+', @ball +{5..8})); given ($result_1) { when (-1) { my $result_2 = ((eval join '+', @ball{1,2,5}) <=> (eval jo +in '+', @ball{3,6,10})); given ($result_2) { when (-1) { my $result_3 = $ball{1} <=> $ball{2}; given ($result_3) { when (-1) { return (1, $result_1) } when (0) { return (6, $result_1 * -1) } when (1) { return (2, $result_1 ) } } } when (0) { my $result_3 = $ball{7} <=> $ball{8}; given ($result_3) { when (-1) { return (8, $result_1 * -1) } when (0) { return (4, $result_1) } when (1) { return (7, $result_1 * -1) } } } when (1) { return $ball{3} == $ball{10} ? (5, $result_ +1*-1 ) : (3, $result_1) } } } when (0) { my $result_2 = ((eval join '+', @ball{9,10}) <=> (eval + join '+', @ball{1,11})); given ($result_2) { when (0) { return (12, $ball{12} <=> $ball{1}) } default { my $result_3 = $ball{9} <=> $ball{10}; given ($result_3) { when (-1) { return ($result_2 == $result_3 ? 9 + : 10, $result_2 == $result_3 ? -1 : 1) } when (0){ return (11, $result_2 * -1) } when (1) { return ($result_2 == $result_3 ? 9 +: 10, $result_2 == $result_3 ? 1 : -1) } } } } } when (1) { my $result_2 = ((eval join '+', @ball{1,5,6}) <=> (eval jo +in '+', @ball{2,7,10})); given ($result_2) { when (-1) { my $result_3 = $ball{5} <=> $ball{6}; given ($result_3) { when (-1) { return (5, $result_1*-1) } when (0) { return (2, $result_1 ) } when (1) { return (6, $result_1 * -1) } } } when (0) { my $result_3 = $ball{3} <=> $ball{4}; given ($result_3) { when (-1) { return (4, $result_1 ) } when (0) { return (8, $result_1*-1) } when (1) { return (3, $result_1 ) } } } when (1) { return $ball{7} == $ball{10} ? (1, $result_ +1 ) : (7, $result_1*-1); } } } } } sub Modify_Ball( %ball ) { my $num = int( rand 12 ) + 1; my $adj = .1 * (int( rand 2 ) ? 1 : -1); $ball{$num} += $adj; say $num; say $ball{$num}; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://917931]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (4)
As of 2024-03-29 06:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found