Forums

Search results: 135

There is also a newer version of compoundProblem5.pl in the development branch, and you can view it or use the "raw" button to get a copy. It simplifies things considerably and adds PGML support, but it is still not quite so easy as the newer scaffold.pl that Mike mentioned.

There is now some documentation at the top of the compoundProblem5.pl file, with a sample shell of a problem. There is a complete example in the pull request. The older code requires you to keep track of all the answers in all the parts, but the new version doesn't, so the Wiki example Mike linked to is more complicated than it has to be now. There is also a new PROCESS_SCAFFOLD() call that takes care of all the details in the bottom section of the Wiki example.

I just noticed that the documentation at the top of the file calls it scaffold.pl rather than compoundProblem5.pl. I will have to change that, but it was that way because I was going to change the name before I wrote the new scaffold.pl from scratch.
This is a good method for the approach you are using.

If you would like a better idea of what data is available to you in any problem, temporarily put "PGinfo.pl" in your loadMacros list  and then use

listVariables();  anywhere in the perl code sections of the problems.  (It doesn't go inside TEXT() function -- it prints itself.)

This will print out a complete list of all of the variables that you can access when writing a PG problem.  You won't need most of them of course.

For your original question about writing a sequential problem which hides the second part until the student gets the first part right  there have been a number of approaches starting with the macro file compoundProblem.pl, through compoundProblem5, and the best of the macro packages is called scaffold.pl (completed by Davide Cervone this summer).  


I think it will do what you want.  scaffold.pl is not yet in either the master or the develop version of pg yet.  It is pull request #153 
https://github.com/openwebwork/pg/pull/153 
so you can download it and install it yourself if you wish.

The best version for scaffolded problems that currently exists in the standard "master" distribution of webwork is compoundProblem5 and is described here: 


(scaffold.pl is better -- so I recommend that if at all possible.)
Here's the whole problem, Davide.  I tried to implement your notation as closely as I could, still with the same results.  The empty set '{}' is still not accepted as the correct answer.

I'm using  ww_version: 2.8, pg_version: 2.8.1.

##DESCRIPTION
## Compound Inequalities
## 
##ENDDESCRIPTION
# Original Problem Author: Modified by Shafiu Jibrin 
#                 from setSets/ur_st_1_2.pg 
# Location: Northern Arizona University
## DBsubject(Set theory)
## DBchapter(Basic properties and operations)
## DBsection(Union and intersection)
## Institution(The College of Idaho)
## Author(RA Cruz)
## Level(2)
## TitleText1('Essentials of Intermediate Algebra')
## AuthorText1('Blitzer')
## EditionText1('1')
## Section1('4.1')
## Problem1('')
## KEYWORDS('inequalities')
## Date: 2007/10

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

loadMacros(
  "PGstandard.pl",
  "PGchoicemacros.pl",
  "MathObjects.pl",
#  "PGgraphmacros.pl",
#  "PGnauGraphics.pl",
#  "contextInequalitiesAllowStrings.pl",
  "answerHints.pl",
#  "CofIdaho_macros.pl"
);

TEXT(beginproblem());

######################################
#  Setup

@slice = NchooseK(12,9);
@A = ($slice[1], $slice[2], $slice[3], $slice[4]);
@B = ($slice[5], $slice[6], $slice[8]);
$AiB = "N";
@AuB = ($slice[1], $slice[2], $slice[3], $slice[4], $slice[5], $slice[6],$slice[8]);

for ($k=3; $k>0; $k-=1) {
  for ($i=0; $i<$k; $i+=1){
    if($A[$i]>$A[$k]) {
       $b = $A[$i];
       $A[$i] = $A[$k];
       $A[$k] = $b;
    }
  }
}

for ($k=2; $k>0; $k-=1) {
  for ($i=0; $i<$k; $i+=1){
    if($B[$i]>$B[$k]) {
       $b = $B[$i];
       $B[$i] = $B[$k];
       $B[$k] = $b;
    }
  }
}


#for ($k=2; $k>0; $k-=1) {
#  for ($i=0; $i<$k; $i+=1){
#    if($AiB[$i]>$AiB[$k]) {
#       $b = $AiB[$i];
#       $AiB[$i] = $AiB[$k];
#       $AiB[$k] = $b;
#    }
#  }
#}

for ($k=6; $k>0; $k-=1) {
  for ($i=0; $i<$k; $i+=1){
    if($AuB[$i]>$AuB[$k]) {
       $b = $AuB[$i];
       $AuB[$i] = $AuB[$k];
       $AuB[$k] = $b;
    }
  }
}

$LEFT_BRACE = '\{';
$RIGHT_BRACE = '\}';
 
Context("Interval");
$ans_a = Set();

######################################
#  Main text

Context()->texStrings;
BEGIN_TEXT

Let \( A= ${LEFT_BRACE} $A[0],  $A[1], $A[2], $A[3] ${RIGHT_BRACE}\) , $SPACE
\( B= ${LEFT_BRACE} $B[0],  $B[1],  $B[2] ${RIGHT_BRACE}\)
$BR
Find the following sets in list form. Separate elements with commas.  If there are no elements in the set, enter "NONE".
$PAR
a) \( A \cap B =  \) \{$ans_a->ans_rule(25) \}
$PAR
b) \( A \cup B = \) \{ans_rule(25)\} 
END_TEXT
Context()->normalStrings;
######################################
#  Answer


ANS($ans_a->cmp);

Context()->parens->replace('{' => {close => '}', type => 'Set'});

# $ans_a = String("NONE");

#ANS($ans_a->cmp->withPostFilter(AnswerHints(
#            sub {
 #              my ($correct,$student,$ans) = @_;
  #              if ($student=~ /\w/) {return $student !~ /[}{]/;}
   #             } => ["Enter your answer with set notation: { ... }", 
    #                  checkCorrect => 1, 
     #                 score => 0]
#)));

$ans_b = Set("{$AuB[0],$AuB[1],$AuB[2],$AuB[3],$AuB[4],$AuB[5],$AuB[6]}");
#Answer hints not working
ANS($ans_b->cmp->withPostFilter(AnswerHints(
            sub {
                my ($correct,$student,$ans) = @_;
                return $student !~ /[}{]/;
                } => ["Enter your answer with set notation: { ... }", 
                      checkCorrect => 1, 
                      score => 0]
)));

$showPartialCorrectAnswers = 1;

######################################


COMMENT('MathObject version');
ENDDOCUMENT();

WeBWorK Problems -> MultiAnswer oddity -> Re: MultiAnswer oddity

by Michael Gage -
This is not a direct reply to your post, but don't expect compoundProblems5/Scaffold and MultiAnswer to always work smoothly together.  They both change the names of answer blanks around and not always in ways that work together.  John Travis and I ran into this while working on some sample questions at Asheville.  The Scaffolding code needs some more work and possibly a new idea to work smoothly with multianswer.  So far compoundProblems5 has worked well with arrays.

WeBWorK Problems -> MultiAnswer oddity

by Peter Staab -
I've been playing with compoundProblem5 and MultiAnswer within it.  I'm getting a strange result where I enter the correct expression  in the first ans_rule and I get the following in the entered column : "-\left(\sin\!\left(4x\right)\right)\tan\!\left(4x\right)/4x"  

and the warning: Unexpected character '\'

It appears that the tex version is being sent as the input.  

Here is the relevant code (the entire problem is about 300 lines, so I'll save you some headaches): 

$top3= Compute("-sin($b*x)*tan($b*x)");
$bottom3 = Compute("$b*x");

$dtop3 = $top3->D;
$dbottom3 = $bottom3->D;

$limit5 = MultiAnswer($top3, $bottom3)->with(
  singleResult => 0,
  allowBlankAnswers => 1,
  checker => sub {
    my ( $correct, $student, $self ) = @_;
    my ($studNum,$studDen) =@{$student};
    my $studentAns = Compute("$studNum/$studDen");
    my ($correctNum,$correntDen) = @{$correct};
    my $correctAns = Compute("$correctNum/$correntDen");
    my $denomLinear =  $studDen->D()->D() == Compute(0);
    $self->setMessage(2,"The denominator must be linear") unless $denomLinear;

    my $result = $studentAns == $correctAns && $denomLinear;

    return $result;
});

if ($displayMode eq 'TeX') {
  $showLimit =
  "\[ $limit  ".$limit5->ans_rule(10).$limit5->ans_rule(10)." \]";
} else {
  $showLimit =
  ColumnTable(
  "\( \displaystyle $limit \)",
  $limit5->ans_rule(20).$BR.$HR.$limit5->ans_rule(20),
  indent => 0, separation => 10, valign => "MIDDLE"
  );
}

Context()->texStrings;
DISPLAY_SECTION(
{ name=>"5: Rewrite and apply L'Hopital's Rule Again", 
    canshow =>$scaffold->requireCorrect(7,8,9). " or $isInstructor",
    iscorrect=>$scaffold->requireCorrect(10,11,12,13), 
    section=>5
},   <<'END_SECTION'); 

You found the limit in the previous section to be

\[ $limit \frac{$top2}{$bottom2} \]

Rewrite this into the form where the bottom is a linear function and the top has trigonometric functions.  (Note: do not apply L'Hopital's Rule)

$showLimit

WeBWorK Problems -> CompoundProblem5 bug

by Peter Staab -
I'm trying to use the new version of compoundProblem (compoundProblem5.pl) and started with the documented one at http://webwork.maa.org/wiki/CompoundProblem5 and I'm running the latest version of the develop branch. 

If I walk through the problem, the 3rd section doesn't open.  Troubleshooting, it looks like at the end of the problem, it opens sections based on

$opensection = $last_correct_section + 1;
$scaffold->openSections($opensection);

and if I print out $opensection, then it equals 0 when the problem first loads, 1 after the correct answer is opened in the first sections, and remains 1 after the 2nd section is correctly solved.