sub check_scheme { my @scheme = @_; ## check that each round measures the same amount of balls for my $round (0 .. 2) { my $lhs = grep { $scheme[$round][$_] eq "L" } 0 .. 11; my $rhs = grep { $scheme[$round][$_] eq "R" } 0 .. 11; return 0 if $lhs != $rhs } ## simulate the scheme with each of the balls being the odd one for my $item (0 .. 11) { my @candidates = (0 .. 11); for my $round (0 .. 2) { if ($scheme[$round][$item] eq "-") { @candidates = grep { $scheme[$round][$_] ne "-" } @candidates; } else { @candidates = grep { $scheme[$round][$_] eq "-" } @candidates; } } ## by this point we should have eliminated all but one ball! return 0 if @candidates != 1; } return 1 }