Find three different factors of 45.

Of course, I want the number randomized. To make sure it has enough factors, I generate it as a product of two random integers in [2,13].

Here are a few problems I've run into and my ideas for solving them.

1. There is no answer checker to check if a number is a factor of another. So I'll need to write my own, along the lines of

sub mycheck_factor {

my ($number, $student, $ansHash) = @_;

return($number % $student == 0);

}

2. I need to check that the three factors are indeed distinct and award partial credit for each correct answer that is distinct from the others.

3. I'd want to fine tune my answer checked so it displays a meaningful correct answer when the assignment closes.

Here is my code which currently asks for and checks only one factor:

DOCUMENT();

loadMacros(

"PGstandard.pl",

"MathObjects.pl"

);

Context("Numeric");

$a = Real(random(2,13));

$b = Real(random(2,13));

$c = $a * $b;

TEXT(beginproblem());

Context()->texStrings;

BEGIN_TEXT

Enter three factors of the number $c:

\{ ans_rule(10) \}, \{ ans_rule(10) \}, \{ ans_rule(10) \}.

END_TEXT

Context()->normalStrings;

sub mycheck_factor {

my ($number, $student, $ansHash) = @_;

return(($student==int($student)) && (int($number) % int($student) == 0));

}

ANS($c->cmp( checker=>~~&mycheck_factor));

ANS($c->cmp( checker=>~~&mycheck_factor));

ANS($c->cmp( checker=>~~&mycheck_factor));

ENDDOCUMENT();

I have the following concerns.

1. The way the numbers are converted to real first and then back to integer seems a rather inelegant hack. I have to set them up as real, since that's the only type of number MathObject knows and without setting it, $c->cmp doesn't really know what to do (gives error message

`'Can't call method "cmp" without a package or object reference`

`'). `

On the other hand, the % operator in Perl refuses to work with real numbers.2. Since the student could enter any kind of number, it is necessary to check if their answer is integer and grade it down if it is not. If they enter a noninteger number, it would be nice to send back a message that divisibility is only defined for integers. I suspect it is possible to do this and the moodle page on Custom Answer Checkers mentions something about including

`Value->Error("message")`

after the error, but I can't figure out how to use this.3. Is there an elegant/efficient way to check that the three numbers entered by the student are distinct, and award 1/3 of the credit for each correct distinct answer?

4. How can I change what is displayed as a correct answer once the homework has closed? Right now, the problem would display $c three times. Could I somehow replace $c with the string "e.g. 1, $a, $c?"

Thank you,

Imre