You could simplify this by making only one answer-hint function for each answer, as in:
ANS(Compute($normProbA[0])->cmp->withPostFilter(AnswerHints(
sub {
my ($correct,$student,$ans) = @_;
return $student < 0 || $student > 1;
} => "Probabilities must be between 0 and 1."
)));
ANS(Compute($normProbB[0])->cmp->withPostFilter(AnswerHints(
sub {
my ($correct,$student,$ans) = @_;
return $student < 0 || $student > 1;
} => "Probabilities must be between 0 and 1."
)));
ANS(Compute($normProbC)->cmp->withPostFilter(AnswerHints(
sub {
my ($correct,$student,$ans) = @_;
return $student < 0 || $student > 1;
} => "Probabilities must be between 0 and 1."
)));
Even better, you could use a common function for all three:
$rangeHint = sub {
my ($correct,$student,$ans) = @_;
return $student < 0 || $student > 1;
};
ANS(Compute($normProbA[0])->cmp->withPostFilter(AnswerHints(
$rangeHint => "Probabilities must be between 0 and 1."
));
ANS(Compute($normProbB[0])->cmp->withPostFilter(AnswerHints(
$rangeHint => "Probabilities must be between 0 and 1."
));
ANS(Compute($normProbC)->cmp->withPostFilter(AnswerHints(
$rangeHint => "Probabilities must be between 0 and 1."
));
Or you could make the whole answer hint into a function:
sub RangeHint {
AnswerHints(
sub {
my ($correct,$student,$ans) = @_;
return $student < 0 || $student > 1;
} => "Probabilities must be between 0 and 1."
);
};
ANS(Compute($normProbA[0])->cmp->withPostFilter(RangeHint));
ANS(Compute($normProbB[0])->cmp->withPostFilter(RangeHint));
ANS(Compute($normProbC)->cmp->withPostFilter(RangeHint));
You could even put the RangeHint function into a macro file and use
includeMacros()
to load it into you problem so that you can use the same code in multiple problems.