I wrote a combinatorial problem like:
"At a bookstore, an ASU student wants to buy 2 mathematics books from
10 math books on differnet subjects. She also needs to buy 3 computer
books from 10 available computer books and 4 English books from 7
available ones. How many differnet choices are there? "
The answer should be C(10,2)*C(10,3)*C(7,4) and I wrote:
$ans1 = [fact($a)/(fact($a1)*fact(8))]; #$a1=$a8
$ans2 = [fact($b)/(fact($b1)*fact(7))]; #$b1=$b7
$ans3 = [fact($c)/(fact($c1)*fact(3))]; #$c1=$c3
$ans = $ans1*$ans2*$ans3;
&ANS(num_cmp($ans));
When I used $ans1, it gave me 45 as correct answer. When I used ans2,
it gave me 120, when used ans3, it gave 35, all correct. However, when
I used ans=ans1*ans2*ans3, it gave a number like 3.0703692407745e+24. I
tried $ans=$ans1+$ans2, or $ans1*$ans2, it also gave me similiar funny
numbers. However, when used $ans=45*120, no problem. Could anybody tell
what could be the problem?
Jun
< Post or View Comments >
