WeBWorK Main Forum

Formula in array or hash

Formula in array or hash

by Zak Zarychta -
Number of replies: 1
Is there a way of stuffing WeBWork formulae into an array or hash to be read by the answer checker ie

Context("Numeric");
Context()->variables->are(a=>'Real',b=>'Real',c=>'Real',d=>'Real');
$a=Formula( a * ( b - c) + d );
$b=Formula( (a * b) - (c + d) );
$c=Formula( a * ((b - c) + d) );

@ans=($a,$b,$c);

foreach my $answers( @ans ) {
ANS( $answers->cmp() );
}

Zak
In reply to Zak Zarychta

Re: Formula in array or hash

by Gavin LaRose -
Hi Zak,

I do things like this fairly regularly, so the answer should be "yes." You may run into trouble with localizing the answer in the loop, however; I've found in some cases localizing a variable in a PG file causes it to be unavailable to the executing environment.

Gavin