WeBWorK Problems

Matching a List up to a constant

Matching a List up to a constant

by Peter Staab -
Number of replies: 1
I'm trying to get WW to check an answer that is a list up to a constant.

That is, if 1,2,3 is correct, then I'd like it to accept 2,4,6, 3,6,9 and 0.5,1,1.5, etc.

I thought that I could build a custom checker that would renormalize the students answer, something like this:

$listChecker = sub {
my ($correct, $student, $ans ) = @_;

$m=absmax($student);
$newList = List($student[0]/$m,$student[1]/$m,$student[2]/$m,$student[3]/$m,$student[4]/$m,$student[5]/$m,$student[6]/$m);

return ($correct==$newList);

};

ANS( Compute($ans1)->cmp( list_checker=>$rowChecker) );

where absmax returns the maximum absolute value of a list and the length should be 7 (a bit klugy).

On a related topic, any suggestions for troubleshooting custom answer checkers?
In reply to Peter Staab

Re: Matching a List up to a constant

by Gavin LaRose -
Hi Peter,

I think something like this should work. What error(s) are you getting? (I assume the use of $rowChecker in the last line is a transcription error.) My experience is that when I'm trying to check custom evaluators I end up having to put in a collection of warn() commands in the checker to see what different values are as the checker processes the answer.

The other thing that I often have to check is what type of object the checker is seeing by echoing out the ref() value of the object.

I don't know if that's useful, but hopefully it's not off base.

Gavin