View Full Version : Random Quest
zack221
04-22-2019, 10:17 AM
Answered..
Sturm
04-22-2019, 12:25 PM
You would have to define each possible turn-in combination.
zack221
04-22-2019, 12:28 PM
ah right ok Thanks
Sturm
04-23-2019, 09:37 AM
Not sure why you redacted your question, it might help someone in the future.
So he asked: How would you make a turn-in that could be 4 of any of the 10 items needed.
c0ncrete
04-23-2019, 03:47 PM
You would have to define each possible turn-in combination.
What? No.
# 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
Sturm
04-23-2019, 04:23 PM
There ya go, if you're a wizard you can do it that way.
See, it pays to leave the original question.
There's always a different way to do things! haha
c0ncrete
04-23-2019, 04:41 PM
Seeing the answer without knowing the question was bugging me. :D
There are always several ways to do something in Perl (using grep instead of the smart matching operator, for example).
Something similar to the example provided would be less error prone, especially if you ever intend to change the items that are required.
vBulletin® v3.8.11, Copyright ©2000-2025, vBulletin Solutions Inc.