WeBWorK Problems

ordering of inner lists in lists of lists

Re: ordering of inner lists in lists of lists

by Davide Cervone -
Number of replies: 0
This problem is occurring because the list answer checker is more complicated than just a == between the two lists. In order to get messages about which entries are correct, and how many more you might need, and such, the list checker handles the unordered lists, whereas == between two lists is a comparison of ordered lists. This is a design decision the has had several undesirable consequences, I'm sorry to say, and so probably is a design flaw.

In any case, in order to do what you are wanting to do, you need to provide your own custom checker. Here is one that gets the job done in your case but may not be completely general (if you were using decimal values, for example this might not be the best approach, but it should be fine for integers).

Note that I also use the entry_type to make a better wording for the entries in error messages ('pair' is better than 'list of numbers' in this case).

ANS($ans->cmp(
  entry_type => 'pair',
  checker => sub {
    my ($correct, $student, $ansh) = @_;
    my $c = List(lex_sort($correct->value));
    my $s = List(lex_sort($student->value));
    return $c == $s;
  }
));