Forum archive 2000-2006

Zbigniew Fiedorowicz - WeBWorK programming question

Zbigniew Fiedorowicz - WeBWorK programming question

by Arnold Pizer -
Number of replies: 0
inactiveTopicWeBWorK programming question topic started 9/17/2003; 9:14:25 PM
last post 9/17/2003; 9:14:25 PM
userZbigniew Fiedorowicz - WeBWorK programming question  blueArrow
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:
##  Algebra problem: Solving linear equations
##  Authored by Rose Hart and Zig Fiedorowicz
##  September, 2003
##KEYWORDS('algebra', 'rational functions')
DOCUMENT();        # This should be the first executable line in the problem.
$a =  random(1,5,1);
$b =  random(1,5,1);
[ frac{$a x}{x- $b} - frac5{$b -x} ]
Answer: {NAMED_ANS_RULE(my_answer,35)}
$ans = "($a*x+5)/(x- $b)";
#First make sure that there are no multiple fractions in the expression
$Answer = $inputs_ref->{my_answer};
$Answer = '' unless defined($Answer);
@chars = split //, $Answer;
$numSlashes = 0;
foreach $char (@chars) {
  if ($char eq '/') {$numSlashes++;}
if ($numSlashes > 1)
ENDDOCUMENT();        # This should be the last executable line in the problem.
Now before I came up with this, I tried the more straightforward regular expression match condition for multiple slashes 
if ((/~~/.*~~/) || ($Answer =~ /~~^/) || ($Answer =~ /~~*~~*/)) 


and got all kinds of funky error messages. Was I doing something blindingly stupid or is there some kink in WeBWorK?

TIA, Zig

<| Post or View Comments |>