## Forum archive 2000-2006

### Gregg Klein - Random Selection of Problems ### Gregg Klein - Random Selection of Problems

by Arnold Pizer -
Number of replies: 0 Random Selection of Problems topic started 7/12/2002; 10:11:27 PMlast post 7/14/2002; 11:16:46 PM Gregg Klein - Random Selection of Problems 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 |> Gavin LaRose - Re: Random Selection of Problems 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] { ans_rule($ansRuleSizes[$index]) }$PAR$BBOLD 2.$EBOLD$probList[$index] { ans_rule($ansRuleSizes[$index]) }END_TEXTANS( $ansEvals[$index] );ANS( $ansEvals[$index] ); 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 |> Gregg Klein - Re: Random Selection of Problems 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#ENDDESCRIPTIONDOCUMENT(); # This should be the first executable line in the problem.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(x + v) =$$","$v*x+$v*$v","$$v(v x + v) =$$","$v*$v*x+$v*$v","$$v(v x + v) =$$","$v*$v*x+$v*$v", "$$v(x + y) =$$","$v*x+$v*y","$$v(x + y + v) =$$","$v*x+$v*y+$v*$v","$$v(v a + b + v c) =$$","$v*$v*a+$v*b+$v*$v*c","$$v(x + v y) =$$","$v*x+$v*$v*y","$$v(v + x) =$$","$v*$v+$v*x", );$thisCourse = $inputs_ref->{'course'};TEXT(EV2(<['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 #1I 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 |> Gregg Klein - Re: Random Selection of Problems 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 |> Mark Schmitt - Re: Random Selection of Problems 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 |>