## WeBWorK Problems

### curious behavior of compoundProblem.pl

by John Perry -
Number of replies: 8
I wrote a WW problem using compoundProblem.pl. I didn’t want to rewrite the text to the first part in subsequent parts, so I formatted the problem as follows:
Does the following Diophantine equation have integer solutions?
$a x + b y = c$
\{ $has_solution->menu() \} #$has_solution is a PopUp
END_TEXT Context->normalStrings;
ANS( $has_solution->cmp() ); if ($part >= 2 ) {
Context->texStrings;
BEGIN_TEXT
Good! What is one possible solution?
$PAR $$x\equiv$$ \{ ans_rule(5) \} END_TEXT Context->normalStrings; # and so forth The key here is that • I have no guard to print the introduction and its answer field for the first part; i.e., no if ($part == 1), and
• I have if ($part >= 2) rather than the documentation’s if ($part == 2) because there’s a third part, too, and I wanted the text in part 2 to stick around there, as well.
As I say, there were three parts total. The upshot is that the answer field for part 1 is counted 3 times (once for part 1, once again for part 2, and a third time for part 3), while the answer field for part 2 was counted twice (once for part 2, and once again for part 3).

So the correct value of totalAnswers when declaring this compoundProblem was 6, not 3 as I originally expected. I say this because when the student gets the answers right, setting totalAnswers to 3 leads to a score of 200% and a mysterious-looking X on the student’s progress page, as well as problems with the student score, whereas setting totalAnswers to 6 leads to a 100% and the expected 100 on the student’s progress page.

I want to make sure this is the desired behavior. It took me a couple of hours to figure out what was going on, so I’d be happy to add a note to the Wiki for the other rare birds like myself who try to do something like this. If this is not the desired behavior, but rather a bug, then of course I’d much prefer to change the problems now so that I do not have to worry about surprises in the future.

### Re: curious behavior of compoundProblem.pl

by Michael Gage -
Hi John,

This isn't directly a reply to your question, but you should be aware that
compoundProblem.pl is deprecated (it is being kept around for backwards compatibility) and it is better to use scaffold.pl

and

which is more flexible and probably easier to use.
(There is also http://webwork.maa.org/wiki/CompoundProblem5 but again this is an older implementation of the scaffolding model.)

Hope this helps.

### Re: curious behavior of compoundProblem.pl

by John Perry -
You aren’t kidding. I just wrote three problems using scaffold.pl, and it worked great! The only downside is that I now have to go back and rewrite my old problems.

That said, the natural place to go looking for help on this is (as far as I know) the Problem Techniques Wiki, and the only techniques listed that obviously apply to multi-part problems are “Compound (Multi-part, sequential) Problems” and “Multi-Part, Sequential Problems”. Both link to a page that has nothing about scaffold.pl. I can edit that page with a note that the techniques listed there are considered obsolete, adding a link to the page on Scaffolding. Is that OK? I’m leery about rushing in; for all I know, there’s a reason it hasn't already been done.

### Re: curious behavior of compoundProblem.pl

by Michael Gage -
It's ok to edit -- in fact we encourage it. Pages are versioned so you can always back out if necessary. It also doesn't hurt to ask before or during edits if you have questions. That may save some time.

{{Historical|Foo [[test]] foo.}}

Which produces a banner about this being a historical document. The second part of the entry gives a link to follow for a more up-to-date information and some explanation.

The only reason this hasn't been done is lack of person-hours. Your help would be very useful.

There are also compoundProblems2.pl, etc as well as sequentialProblems.pl. The development of the right mechanism took many iterations of development over about 10 years.

The current version is quite powerful and could use a full length blog post about how to use it creatively. (That could be placed on the wiki or sometimes it gets more publicity if it's contributed to the blog aggregator reached by the "blogs" link in the left margin of the wiki. ) It's most lack of time that keeps documentation from being higher priority. :-)



Glad this is now working well for you and I look forward to the problems you produce while experimenting with it. I think scaffolded.pl problems have a lot of potential that is only beginning to be investigated. Thanks for letting us know how things turned out.

### Re: curious behavior of compoundProblem.pl

by John Perry -
I’ve now modified the relevant page. But:

The template you showed doesn't appear on the page you gave, and doesn't work the way you suggested. That MediaWiki page also provided an Obsolete template, so I tried that, but it also doesn’t work according to their documentation.

So I added both those tags/templates, as well as a separate paragraph redirecting the user. Finally, on the Problem Techniques page I added a “see also”.

Let me know if that was OK, or if any of it should change.

### Re: curious behavior of compoundProblem.pl

by Michael Gage -
Thanks John. I admit I don't understand the MediaWiki templates very well either and some of their documentation is out of date. (So I guess WeBWorK is in good company in that regard.)

After much futzing around I've created a new template:

Template:OutdatedRedirect
which accepts an additional parameter, any phrase you want.
{{OutdatedRedirect | You can write multi-part problems using the [[Scaffold|scaffold.pl]] macro file }}

gives you

 Outdated IMPORTANT: The content of this page is outdated. Do not rely on the information contained in this page. You can write multi-part problems using the scaffold.pl macro file.

The template is at Template:OutdatedRedirect in the Altert_templates category:

Someone with more knowledge can got ahead and improve this template (and others in that category). Then we can update all the wiki pages to use OutdatedRedirect to point to the current information.

Thanks for the help.

-- Mike

### Re: curious behavior of compoundProblem.pl

by John Perry -
Thank you. I see that you also modified the page for compound problems, as well, so it looks as if this is completely resolved.

### Re: curious behavior of compoundProblem.pl

by Davide Cervone -
Mike is right, the compundProblem.pl macros are very old and no longer supported, and the scaffold.pl macros are much better and easier to use. In particular, you don't have to keep track to the number of problems, as you did with compoundProblem.pl.

You don't give enough of your problem code to really check what you are doing, but compoundProblem isn't designed to do what you are trying to do (you can't have the same answer rules show up in more than one part, as you appear to be doing, or they will count as answers in both parts, and I'm not sure that will be graded correctly even if you do.

Fortunately, the scaffold macros are set up to provide more flexibility, and you can have previous parts open when later parts are being displayed.

Here is an example of what I think you are after:

loadMacros(
"scaffold.pl",
"parserPopUp.pl",
);

Context("Numeric");
Context->strings->are(yes=>{}, no=>{});

Scaffold::Begin(is_open => 'correct_or_first_incorrect');

$a = random(2,5,1);$b = random(3,7,1);
$x = random(1,5,1);$y = random(2,6,1);
$c =$a * $x +$b * $y;$p = PopUp(["?","yes","no"],"yes");

$ma = MultiAnswer($x,$y)->with( checker => sub { my ($C, $S) = @_; my ($x, $y) = @$S;
return $a *$x + $b *$y == $c &&$x == int($x) &&$y == int($y); } ); Section::Begin("Part 1: The Equation"); BEGIN_TEXT Does the following Diophantine equation have integer solutions?$PAR
$a x + b y = c$
\{ $p->menu \} END_TEXT ANS($p->cmp);

Section::End();

Section::Begin("Part 2: The Solution");

BEGIN_TEXT
Good! What is one possible solution?
$PAR $$x\equiv$$ \{$ma->ans_rule(5) \} and $$y\equiv$$ \{ $ma->ans_rule(5) \} END_TEXT ANS($ma->cmp);

Section::End();

Scaffold::End();


You should be able to start with this and modify it to your needs. See the scaffold.pl documentation for details.