## Forum archive 2000-2006

### Zbigniew Fiedorowicz - WeBWorK programming question

by Arnold Pizer -
Number of replies: 0
 WeBWorK programming question topic started 9/17/2003; 9:14:25 PMlast 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: 
##DESCRIPTION##  Algebra problem: Solving linear equations##  Authored by Rose Hart and Zig Fiedorowicz##  September, 2003##ENDDESCRIPTION##KEYWORDS('algebra', 'rational functions')DOCUMENT();        # This should be the first executable line in the problem.loadMacros(PG.pl,PGbasicmacros.pl,PGchoicemacros.pl,PGanswermacros.pl,PGauxiliaryFunctions.pl);TEXT(&beginproblem);$a = random(1,5,1);$b =  random(1,5,1);TEXT(EV2(<{my_answer};$Answer = '' unless defined($Answer);@chars = split //, $Answer;$numSlashes = 0;foreach $char (@chars) { if ($char eq '/') {$numSlashes++;}}if ($numSlashes > 1)     {NAMED_ANS(my_answer,strict_str_cmp($ans));}else {NAMED_ANS(my_answer,function_cmp($ans));}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 |>