Interesting problem, but I think I've got it. My solution involves creating six lists and uses the assumption that the select questions and ranking questions are named with a simple base name with an incrementer (e.g., "SelectQ1," "SelectQ2," and "RankingQ1," "RankingQ2).
The first list should be a predefined list with one item for each select question.
Then create four constructed lists. Each should use that predefined list for its parent and should have this code:
Begin Unverified Perl
# Parameters
my $parentList = 'list1';
my $selectQBaseName = 'SelectQ';
my $thisListRanking = 1;
# Run
my $items = LISTLENGTH($parentList);
for (my $i = 1; $i <= $items; $i++) {
if (GETVALUE($selectQBaseName . $i) == $thisListRanking) {
ADD($parentList, $i);
}
}
End Unverified
Line 3 must be updated with the name of the predefined list, and line 4 must be updated with the base name of the select questions. Line 6 should be updated with a different value for each of the four lists: 1, 2, 3, 4. These lists can be used in your ranking questions.
Finally, one last constructed list to bring it all together. Same parent list as the others, but now with this script:
Begin Unverified Perl
# Parameters
my $parentList = 'list1';
my $rankingQBaseName = 'RankingQ';
my $numberOfRankingQuestions = 4;
# Run
my $numberOfItems = LISTLENGTH($parentList);
for (my $r = 1; $r <= $numberOfRankingQuestions; $r++) {
my %hash = ();
for (my $i = 1; $i <= $numberOfItems; $i++) {
my $val = GETVALUE($rankingQBaseName . $r . '_' . $i);
if ($val) {
$hash{$i} = $val;
}
}
foreach my $item (sort { $hash{$a} <=> $hash{$b} } keys(%hash)) {
ADD($parentList, $item);
}
}
End Unverified
Line 3 and 4 must be updated.