## WeBWorK Problems

by Bruce Yoshiwara -
Number of replies: 0
Thanks Paul.

I modified your suggestion (and an earlier one from Davide Cervone) to accommodate relatively large tables. So after defining a function $f and the desired number of sets of x and y values that lie on the graph,$ma = MultiAnswer("$ans[0]","$ans[1]",
"$ans[2]","$ans[3]", "$ans[4]","$ans[5]",
"$ans[6]","$ans[7]")->with(
checker => sub {
my ($correct,$student,$ans) = @_; my @score = (0) x scalar(@$correct);
$pairs = scalar(@$correct)/2-1;
ANSWER: foreach my $i (0..$pairs) {
if ($student->[2*$i] ne "" && $student->[2*$i+1] ne "") {
foreach my $j (0..$i-1) {
if ($student->[2*$j] ne "" && $student->[2*$i] == $student->[2*$j]
&& $student->[2*$j+1] ne "" && $student->[2*$i+1] == $student->[2*$j+1])
{
$ma->setMessage(2*$i+1,"This is the same as your ".
$ma->NameForNumber(2*$j+1)." solution.");
}
}
my ($x,$y) = ($student->[2*$i]->value, $student->[2*$i+1]->value);
$score[2*$i] = ($f->eval(x=>$x) == $y);$score[2*$i+1] = ($f->eval(x=>$x) ==$y);
}
}
return @score;
}
);

It seems to work.