2017 Problem Authoring Workshop

Problems which ask for examples

Problems which ask for examples

by Oscar Levin -
Number of replies: 2
This is probably an advanced topic, but I ran into it while writing problems for week 1 homework. The specific problem I want to write is this:

"Give an example of sets A and B with |A| = 4, |B| = 6, and |A U B| = 8."

Of course there are infinitely many correct answers, but I should be able to check whether an answer is correct. To do so though, I would need to take the student's answer run some code on it (perhaps, if len(A) == 4 && len(B) == 6 && len(union(A,B)) == 8, return true; where I might need to define the union function, depending on what perl knows how to do already).

I'm not too worried about figuring out the code to check the answer, but how do I get access to what the student gives as their answer?
In reply to Oscar Levin

Re: Problems which ask for examples

by Gavin LaRose -
Hi Oscar,

We'll be talking about this more in the next week or so. The short answer is that we want to use a custom checker (see http://webwork.maa.org/wiki/CustomAnswerCheckers) for this type of thing to find the student's answer and determine that it's correct.

Gavin
In reply to Oscar Levin

Re: Problems which ask for examples

by Davide Cervone -
To be able to work with several answers at once, you need to use the MultiAnswer object available in the parserMultiAnswer.pl macro file. You get access to the student answers through the custom checker function that you provide. See the MultiAnswer documentation for details.

Here is an example of how to do this:

loadMacros(
  "PGstandard.pl",
  "MathObjects.pl",
  "PGML.pl",
  "parserMultiAnswer.pl",
  "PGcourse.pl"
);

Context("Interval");

$A = Compute("{1,2,3,4}");
$B = Compute("{3,4,5,6,7,8}");

$ma = MultiAnswer($A,$B)->with(
  singleResult => true,
  format => "A = %s and B = %s",
  tex_format => "A = %s\hbox{ and }B = %s",
  checker => sub {
    my ($correct, $student, $m, $ans) = @_;
    my ($A, $B) = @$student;
    if (!$ans->{isPreview}) {
      Value->Error("A doesn't have 4 elements") if $A->length != 4;
      Value->Error("B doesn't have 6 elements") if $B->length != 6;
      Value->Error("The union doesn't have 8 elements") if ($A + $B)->length != 8;
    }
    return $A->length == 4 && $B->length == 6 && ($A + $B)->length == 8;
  }
);

BEGIN_PGML
Give an example of sets [`A`] and [`B`] of numbers with [`|A| = 4`], [`|B| = 6`], and [`|A \cup B| = 8`].

>> [`A`] = [______________]{$ma} and [`B`] = [_______________]{$ma}  <<
END_PGML
Note that I have specified "set of numbers" in the problem because MathObejct sets are only for real numbers. I hope that answers the question.