Forum archive 2000-2006

Gregg Klein - Random Selection of Problems

Gregg Klein - Random Selection of Problems

by Arnold Pizer -
Number of replies: 0
inactiveTopicRandom Selection of Problems topic started 7/12/2002; 10:11:27 PM
last post 7/14/2002; 11:16:46 PM
userGregg Klein - Random Selection of Problems  blueArrow
7/12/2002; 10:11:27 PM (reads: 1515, responses: 4)
I wanted to create say 50 problems and have webwork chose 10 of them. I tweaked the true/false example and I got it to work. However, I have little control over the answer box size and it is on the left (like a true/false... of course)

The particular problem can be seen at here

Set0 problem #1 Login: smith password: 123456

There probably is an easier way to do this. Any help would be appreciated.

<| Post or View Comments |>


userGavin LaRose - Re: Random Selection of Problems  blueArrow
7/14/2002; 4:53:06 AM (reads: 1768, responses: 0)
Hi Gregg,

How long are the problems? The following is a brute force solution to randomly selecting problems which would be less and less attractive the more problems you had. There's an old NchooseK() function somewhere in WeBWorK which would probably be faster than my selection, but I didn't bother to go and plug it in.

Sample code:

$a = random(2,5,1);
$b = random(2,5,1);
$c = random(1,5,1);



@probList = ( 'All continuous functions are differentiable.',
'All polynomials are differentiable.',
'The most common equation for a line is y = ',
'The y-intercept of the intersection of (y=1-x) and' .
' (y=x^3-x) is ',
"Find the derivative of \(f(x)=$a x^3+$b x^2+x\)" );
@ansRuleSizes = ( 3,3,15,3,25 );
@ansEvals = ( str_cmp('F'),
str_cmp('T'),
fun_cmp('m*x + b','var'=>['m','x','b']),
num_cmp(1),
fun_cmp("3*$a*x^2 + 2*$b*x + 1") );
$numPicked = 0;
$whichPicked = '';
$which = random(0,4,1);
@index = ();
while( $numPicked < 2 ) {
if ( $whichPicked !~ /$which,/ ) {
$index[$numPicked++] = $which;
$whichPicked .= "$which,";
}
$which = random(0,4,1);
}



BEGIN_TEXT
$BBOLD 1. $EBOLD
$probList[$index[0]] { ans_rule($ansRuleSizes[$index[0]]) }
$PAR
$BBOLD 2. $EBOLD
$probList[$index[1]] { ans_rule($ansRuleSizes[$index[1]]) }
END_TEXT

ANS( $ansEvals[$index[0]] );
ANS( $ansEvals[$index[1]] );

I'm not sure if that's what you were looking for, but there it is for your inspection, in any event. I suspect there might be some other lurkers on the list with a more elegant solution than my off the cuff version.

Cheers,
Gavin

<| Post or View Comments |>


userGregg Klein - Re: Random Selection of Problems  blueArrow
7/14/2002; 1:32:33 PM (reads: 1749, responses: 0)
Gavin,

The problems are quite short. I will try this and let you know how it works. Thanks.

I tried it and this is what I received: (1 pt) 1. The y-intercept of the intersection of (y=1-x) and (y=x^3-x) is ans_rule(3) 2. All continuous functions are differentiable. ans_rule(3)

I tried to tweak the t/f example of webwork here is my version:

#DESCRIPTION
#ENDDESCRIPTION



DOCUMENT(); # This should be the first executable line in the problem.



loadMacros(PG.pl,
PGbasicmacros.pl,
PGchoicemacros.pl,
PGanswermacros.pl,
PGauxiliaryFunctions.pl);



TEXT(&beginproblem);
$showPartialCorrectAnswers = 0;




for ($i = 0; $i < 18; $i++) {$v[$i] = random(1, 10, 1);}
$n = random(3,8,1);




@questions = ();
@answers = ();
qa(~~@questions, ~~@answers,
"\( $v[0](x + $v[1]) = \)",
"$v[0]*x+$v[0]*$v[1]",



"\( $v[2]($v[3] x + $v[4]) = \)",
"$v[2]*$v[3]*x+$v[2]*$v[4]",



"\( $v[5]($v[6] x + $v[7]) = \)",
"$v[5]*$v[6]*x+$v[5]*$v[7]",



"\( $v[8](x + y) = \)",
"$v[8]*x+$v[8]*y",

"\( $v[9](x + y + $v[10]) = \)",
"$v[9]*x+$v[9]*y+$v[9]*$v[10]",

"\( $v[11]($v[12] a + b + $v[13] c) = \)",
"$v[11]*$v[12]*a+$v[11]*b+$v[11]*$v[13]*c",



"\( $v[14](x + $v[15] y) = \)",
"$v[14]*x+$v[14]*$v[15]*y",



"\( $v[16]($v[17] + x) = \)",
"$v[16]*$v[17]+$v[16]*x",




);
$thisCourse = $inputs_ref->{'course'};




TEXT(EV2(<<EOT));
Enter Directions Here $PAR
You must get all of the answers correct to receive credit.$BR
EOT
@slice = NchooseK(scalar(@questions),$n);



TEXT(
&match_questions_list(@questions[@slice])
);
&ANS (fun_cmp( [ @answers[@slice] ], var=>['x','y','a','b','c'] ) );



ENDDOCUMENT(); # This should be the last executable line in the problem.



Could you check out my problem by clicking here. smith 123456 is the user/password SET0 prob #1

I would like to have answer box to the right of the question and be able to adjust the size of the answer box. I am still trying to get yours to work. Maybe you could look at the code of my version above and fix that if I can't get yours to work (even though it probably does.)

Thanks,

Gregg

<| Post or View Comments |>


userGregg Klein - Re: Random Selection of Problems  blueArrow
7/14/2002; 3:59:16 PM (reads: 1747, responses: 0)
Gavin,

Thanks,

I got yours to work. I had to add \{ \} around the answer box in your code.

I think I got my version to work as well !!

I had to change &match_questions_list(@questions[@slice])

to

&match_questions_list_varbox(10, @questions[@slice])

The answer boxes are still to the left, but I guess I can cope with that.

Thanks,

Gregg

<| Post or View Comments |>


userMark Schmitt - Re: Random Selection of Problems  blueArrow
7/14/2002; 11:16:46 PM (reads: 1782, responses: 0)
Gregg,

If you want the answerbox to come after the question, you can add the following code to PGchoicemacros.pl. I've just editted match_questions_list_varbox, moving the ans_rule to the end of each question.

Hope this helps.

Mark

 

sub match_questions_list_varbox_question_first {
my ($length, @questions) = @_;
my $out = "";
if ($main::displayMode eq 'HTML' || $main::displayMode eq 'HTML_tth') {
my $i=1; my $quest;
foreach $quest (@questions) {
$out.= "\n
$i. $quest". ans_rule($length);
$i++;
}
$out .= "
n";
} elsif ($main::displayMode eq 'Latex2HTML') {
my $i=1; my $quest;
foreach $quest (@questions) {
$out.= " \\begin{rawhtml}
\end{rawhtml} $i. \begin{rawhtml}\end{rawhtml} $quest". ans_rule($length); #"$i. $quest";
$i++;
}
$out .= " \\begin{rawhtml}
\end{rawhtml} ";
} elsif ($main::displayMode eq 'TeX') {
$out = "\n\\par\\begin{enumerate}\n";
my $i=1; my $quest;
foreach $quest (@questions) {
$out .= "\\item[$i.] $quest\n".ans_rule($length);
$i++;
}
$out .= "\\end{enumerate}\n";
} else {
$out = "Error: PGchoicemacros: match_questions_list_varbox: Unknown displayMode: $main::displayMode.\n";
}
$out;
}

<| Post or View Comments |>