I know how to do this with a normal problem:
ANS($ans_eval1 );
$ans_hash1 = $ans_eval1->evaluate($inputs_ref->{ANS_NUM_TO_NAME(1)});
if (1 == $ans_hash1->{score}) {
rest of the steps in the question
}
However I am trying to modify a problem from PCC that uses its own checker in a macro (and PGML). How do I check if the previous answer(s) is (are) correct?
I think I just don't really understand how to access the previous answers very clearly in WeBWorK yet.
Here is the code for the problem itself (It's in the Contrib area of the OPL on github.) See the macro "SolveLinearEquationPCC.pl" for the checker itself.
# WeBWorK problem written by Carl Yao
# Portland Community College
#
# Solve equations like 5x/4-6x=3/8; answer is a fraction or integer.
#
# Last edited: Kling, 7/18/13; Jordan, 7/10/13; Hughes 7/1/13, Wherry, 6/28/13
# ENDDESCRIPTION
## DBsubject('Algebra')
## DBchapter('Basic Algebra')
## DBsection('Algebraic Expressions')
## KEYWORDS('solve','linear','equation','fraction')
## DBCCSS('6.EE.7','7.EE.4','8.EE.7')
## TitleText1('')
## EditionText1('')
## AuthorText1('')
## Section1('')
## Problem1('')
## Author('Alex Jordan, Carl Yao, Chris Hughes')
## Institution('PCC')
##############################################
DOCUMENT();
loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"PGML.pl",
"parserAssignment.pl",
"PCCmacros.pl",
"answerHints.pl",
"contextFraction.pl",
"SolveLinearEquationPCC.pl",
"PGcourse.pl",
);
##############################################
Context("Fraction");
$var = RandomVariableName();
Context()->variables->are($var => 'Real');
Context()->noreduce('(-x)-y','(-x)+y');
$den1 = random(2,10,2);
$num1 = random(3,9,2);
while (gcd($den1,$num1)!=1) {$num1=random(3,9,2);}
$den2 = 2*$den1;
$num2 = random(3,9,2);
while (gcd($den2,$num2)!=1) {$num2=random(3,9,2);}
#adjust $a's value to make the solution negative
$a=random(5,10,1);
$ans = Fraction($num2*$den1,$num1*$den2-$a*$den1*$den2)->reduce;
@answ = $ans->value;
$ansNum = -$answ[0];
$ansDen = $answ[1];
$frac2 = Fraction($num2,$den2);
$left = Formula("$num1*$var/$den1-$a*$var");
$right = Formula("$frac2");
@vArray = ($var);
@aArray = ($ans);
($ansEqRef, $eqTypesRef) = contextSetup(~~@vArray, ~~@aArray);
##############################################
TEXT(beginproblem());
BEGIN_PGML
[@instructions(~~@vArray)@]**
[`` [$left]=[$right] ``]
[_______________________________]
END_PGML
##############################################
answerCheck($ansEqRef, $eqTypesRef);
##############################################
$step1 = $den2*$num1/$den1;
$step2 = $a*$den2;
$step3 = $step1-$step2;
if ($ansDen!=1) {$ansOutput="-\frac{$ansNum}{$ansDen}";}
else {$ansOutput="-$ansNum";}
BEGIN_PGML_SOLUTION
To clear fractions from an equation, multiply each side of the equation by a common denominator. For this problem, a common denominator is [`[$den2]`].
[``
\begin{aligned}
\frac{[$num1][$var]}{[$den1]} - [$a][$var] &= \frac{[$num2]}{[$den2]} \\
[$den2] \cdot \left(\frac{[$num1][$var]}{[$den1]} - [$a][$var]\right) &= [$den2] \cdot \frac{[$num2]}{[$den2]} \\
[$den2] \cdot \frac{[$num1][$var]}{[$den1]} - [$den2] \cdot [$a][$var] &= [$den2] \cdot \frac{[$num2]}{[$den2]} \\
[$step1][$var] - [$step2][$var] &= [$num2] \\
[$step3][$var] &= [$num2] \\
\frac{[$step3][$var]}{[$step3]} &= \frac{[$num2]}{[$step3]} \\
[$var] &= [$ansOutput]
\end{aligned}
``]
[@summary($ansEqRef->[0],$left,$right);@]**
END_PGML_SOLUTION
ENDDOCUMENT();