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 $result_1 = [+] %ball{1..4} <=> [+] %ball{5..8}; given $result_1 { when 0 { my $result_2 = [+] %ball{9,10} <=> [+] %ball{1,11}; given $result_2 { when 0 { return (12, %ball{12} <=> %ball{0}) } default { my $result_3 = %ball{9} <=> %ball{10}; given $result_3 { when -1 { return (9, $result_2 == $result_3 ?? -1 :: 1 } when 0 { return (11, $result_2 * -1 } when 1 { return (10, $result_2 == $result_3 ?? 1 :: -1 } } } } } default { my $result_2 = [+] %ball{1,2,5} <=> [+] %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 * -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); } } } } } 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; }