WeBWorK programming question |
topic started 9/17/2003; 9:14:25 PM last post 9/17/2003; 9:14:25 PM |

Zbigniew Fiedorowicz - WeBWorK programming question 9/17/2003; 9:14:25 PM (reads: 576, responses: 0) |

I
was writing an algebra simplification problem for a colleague, which
asks a student to simplify an expression involving the difference of
two rational functions. The challenge here is to make sure that the
student is really simplifying, not just reentering the original
difference expression, perhaps by cloaking it with negative exponents.
So the idea is to peek at the student's answer before passing it on to
function_cmp(), to rule out multiple /'s, ^'s and **'s. Here's what I
finally came up with: <pre> ##DESCRIPTION ##KEYWORDS('algebra', 'rational functions') DOCUMENT(); # This should be the first executable line in the problem. loadMacros( TEXT(&beginproblem); TEXT(EV2(<<EOT)); $ans = "($a*x+5)/(x- $b)"; #First make sure that there are no multiple fractions in the expression foreach $char (@chars) { if ($numSlashes > 1) ENDDOCUMENT(); # This should be the last executable line in the problem. </pre> Now before I came up with this, I tried the more straightforward regular expression match condition for multiple slashes <pre> if ((/~~/.*~~/) || ($Answer =~ /~~^/) || ($Answer =~ /~~*~~*/)) </pre> and got all kinds of funky error messages. Was I doing something blindingly stupid or is there some kink in WeBWorK? TIA, Zig |