Quote:
Originally Posted by Sturm
You would have to define each possible turn-in combination.
|
What? No.
Code:
# list of 10 possible item ids
my @find = (
0,
1,
2,
3,
4,
5,
6,
7,
8,
9
);
# items found
my @found;
# items turned in (automatically exported in API)
# (item id => count)
my %itemcount = (
1 => 1,
3 => 1,
7 => 2,
a => 1
);
foreach my $item (keys %itemcount) {
# validate item and make sure it is unique
if ((grep /$item/, @find) && (!grep /$item/, @found)) {
push @found, $item;
}
# only required if count will be less than 4 (max item ids that can be turned in)
last if (@found == 4);
}
print "found " . scalar @found . " of 4 required items ";
# minimum number of validated items
if (@found == 4) {
print "(PASS)\n";
# to accept only one of each validated item handed in - UNTESTED
# plugin::check_handin(\%itemcount, map { $_ => 1 } @found);
} else {
print "(FAIL)\n";
}
note: the above example assumes 4 unique item ids are required for success