## WeBWorK Problems

### How to enter/check ordered list

by Siman Wong -
Number of replies: 2
Could anyone recommend a good way to implement ordered lists of variable length? E.g. a student would enter {1,2,3,4,5} which is not the same as {2,1,3,4,5}. If not: what's the best/simplest way to implement this?

Bonus question: what about checking ordered lists up to cyclic permutations -- i.e. {1,2,3,4,5} = {2,3,4,5,1} = {3,4,5,1,2} etc. ?

Thanks!

### Re: How to enter/check ordered list

by Gavin LaRose -
Hi Sima,

See http://webwork.maa.org/wiki/ListAnswers . You should be able to allow cyclic permutations with a custom checker: http://webwork.maa.org/wiki/CustomAnswerCheckers .

Gavin

### Re: How to enter/check ordered list

by Davide Cervone -
Gavin has already pointed you to some documentation about the list answer checker. Here is a sample code snippet that does the cyclic permutation checking via a custom list checker:
    $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