$ans = Compute("{1,2,3}"); # the correct answer
Context()->texStrings;
BEGIN_TEXT
\($ans\) = \{ans_rule(20)\}
END_TEXT
Context()->normalStrings;
ANS($ans->cmp(
requireParenMatch=>1, removeParens=>0, implicitList=>0,
list_checker => sub {
my ($correct,$student,$ans) = @_;
$correct = List(@$correct); # a List from the correct answer
my @student = @$student; # student answer as array
my $n = scalar(@student); # number of elements in student answer
foreach $i (1..$n) {
return $n if $correct == List(@student); # return n entries correct if permutation is correct
push(@student,shift(@student)); # rotate the student answer
}
return 0; # return no entries correct
}
));
The requireParenMatch=>1
, removeParens=>0
, implicitList=>0
are to make sure the student types the braces as part of the list (otherwise (1,2,3)
or even 1,2,3
would also be accepted).
Hope that helps.
Davide