[npl] / trunk / NationalProblemLibrary / maCalcDB / setAlgebra01RealNumbers / sw1_2_15b.pg Repository: Repository Listing bbplugincoursesdistsnplrochestersystemwww

# View of /trunk/NationalProblemLibrary/maCalcDB/setAlgebra01RealNumbers/sw1_2_15b.pg

Sat Jun 3 14:24:38 2006 UTC (6 years, 11 months ago) by gage
File size: 1490 byte(s)
Cleaned up code using convert-functions.pl


    1 #DESCRIPTION
2 ##  Algebra problem: simplifying fraction
3 ##ENDDESCRIPTION
4
5 ##KEYWORDS('algebra', 'fraction')
6 ## hcao tagged and PAID on 2-20-2004
7
8 ## DBsubject('Algebra')
9 ## DBchapter('Basic Algebra')
10 ## DBsection('Real Numbers')
11 ## Date('6/3/2002')
12 ## Author('')
13 ## Institution('')
14 ## TitleText1('College Algebra')
15 ## EditionText1('3')
16 ## AuthorText1('Stewart, Redlin, Watson')
17 ## Section1('1.2')
18 ## Problem1('15b')
19 DOCUMENT();        # This should be the first executable line in the problem.
20
22 "PG.pl",
23 "PGbasicmacros.pl",
24 "PGchoicemacros.pl",
26 "PGauxiliaryFunctions.pl"
27 );
28 TEXT(beginproblem());
29 $showCorrectPartialAnswers = 1; 30 31$n1 = random(2,10,1);
32 $n2 = random(1,10,1); 33$d2 = random(2,10,1);
34
35 BEGIN_TEXT
37              $\left(n1\div\frac{n2}{d2}\right)-\frac{n2}{d2}$
38 The reduced answer is \{ans_rule(5)\} / \{ans_rule(5)\}
39 END_TEXT
40 @factors = ();
41 @commonfactors = ();
42 $fac =$d2*$n2; 43 for($i=2; $i<=($d2*$n2)/2;$i++){
44   if($fac %$i == 0){
45     $fac =$fac/$i; 46 push @factors,$i;
47                 $i =$i-1;
48   };
49 };
50 $fac =$n1*$d2*$d2-$n2*$n2;
51 foreach $i (@factors){ 52 if($fac % $i == 0){ 53$fac = $fac /$i;
54     push @commonfactors,$i; 55 }; 56 }; 57$den = $d2*$n2;
58 $num =$n1*$d2*$d2-$n2*$n2;
59 foreach $i (@commonfactors){ 60$num = $num /$i;
61   $den =$den / $i; 62 }; 63 64 ANS(num_cmp($num, mode=>"strict"));
65 ANS(num_cmp(\$den, mode=>"strict"));
66
67 ENDDOCUMENT();        # This should be the last executable line in the problem.