Solver Permutations and Combinations (with NPR and NCR)
Algebra
->
Algebra
->
Probability-and-statistics
-> Solver Permutations and Combinations (with NPR and NCR)
Log On
Ad:
Algebrator™
solves your algebra problems and provides step-by-step explanations!
Ad:
Algebra Solved!™
: algebra software solves algebra homework problems with step-by-step help!
Algebra: Probability and statistics
Solvers
Lessons
Problems, free tutors
Quiz
In Depth
Source code of 'Permutations and Combinations (with NPR and NCR)'
This Solver (Permutations and Combinations (with NPR and NCR))
was created by by
jim_thompson5910(13794)
:
View Source
,
Show
,
Put on YOUR site
About jim_thompson5910
:
==section input Enter whole number values for n and r (where n goes in the first box and r goes in the second one) and choose between {{{nPr}}} or {{{nCr}}} to calculate the permutation or combination *[input n=5] *[choice path NPR NCR] *[input r=5] ==section solution perl sub CommaFormatted { my $delimiter = ','; # replace comma if desired my($n,$d) = split /\./,shift,2; my @a = (); while($n =~ /\d\d\d\d/) { $n =~ s/(\d\d\d)$//; unshift @a,$1; } unshift @a,$n; $n = join $delimiter,@a; $n = "$n\.$d" if $d =~ /\d/; return $n; } sub fac { my ($n) = @_; if($n==0) { return 1;} if ($n < 2) { return $n; } else { return $n * fac($n-1); } } $npr=fac($n)/(fac($n-$r)); $ncr=fac($n)/(fac($n-$r)*fac($r)); $result=fac($n); if($n<$r) {print "The value of n must be greater than r."; return undef;} if(($n=~m/\D/)||($r=~m/\D/)) {print "You must enter whole numbers only."; return undef;} if($result=~m/e\+(\d+)/) {$ee=$1;} $ee=~s/^0//; if($n>150) {print "Overflow: $n is way too large"; return undef;} if($n>17) {print "Sorry the computer cannot accurately calculate and display $n! (the resulting factorial has $ee digits!)"; return undef;} ## NPR if($path eq NPR) { print "Start with the given expression \*\[Tex \\LARGE \\textrm{_{n}P_{r}=\\frac{n!}{(n-r)!}}] \*\[Tex \\LARGE \\textrm{_{$n}P_{$r}=\\frac{$n!}{($n-$r)!}}] Plug in {{{n=$n}}} and {{{r=$r}}} \*\[Tex \\LARGE \\textrm{_{$n}P_{$r}=\\frac{$n!}{",$n-$r,"!}}] Subtract {{{$n-$r}}} to get ",$n-$r," \*\[Tex \\LARGE \\textrm{_{$n}P_{$r}=\\frac{",fac($n),"}{",$n-$r,"!}}] Calculate $n! to get ",CommaFormatted(fac($n))," (note: if you need help with factorials, check out this <a href=http://www.algebra.com/algebra/homework/Probability-and-statistics/factorial.solver>solver</a>) \*\[Tex \\LARGE \\textrm{_{$n}P_{$r}=\\frac{",fac($n),"}{",fac($n-$r),"}}] Calculate ",$n-$r,"! to get ",CommaFormatted(fac($n-$r))," \*\[Tex \\LARGE \\textrm{_{$n}P_{$r}=",fac($n)/fac($n-$r),"] Divide ",CommaFormatted(fac($n))," by ",CommaFormatted(fac($n-$r))," to get ",CommaFormatted(fac($n)/(fac($n-$r)))," So $n choose $r (where order does matter) yields ",CommaFormatted(fac($n)/(fac($n-$r)))," unique combination", ($npr>1)?"s":" "; } ## END NPR ## NCR if($path eq NCR) { print "Start with the given expression \*\[Tex \\LARGE \\textrm{_{n}C_{r}=\\frac{n!}{(n-r)!r!}}] \*\[Tex \\LARGE \\textrm{_{$n}C_{$r}=\\frac{$n!}{($n-$r)!$r!}}] Plug in {{{n=$n}}} and {{{r=$r}}} \*\[Tex \\LARGE \\textrm{_{$n}C_{$r}=\\frac{$n!}{",$n-$r,"!$r!}}] Subtract {{{$n-$r}}} to get ",$n-$r," \*\[Tex \\LARGE \\textrm{_{$n}C_{$r}=\\frac{",fac($n),"}{",$n-$r,"!$r!}}] Calculate $n! to get ",CommaFormatted(fac($n))," (note: if you need help with factorials, check out this <a href=http://www.algebra.com/algebra/homework/Probability-and-statistics/factorial.solver>solver</a>) \*\[Tex \\LARGE \\textrm{_{$n}C_{$r}=\\frac{",fac($n),"}{(",fac($n-$r),")($r!)}}] Calculate ",$n-$r,"! to get ",CommaFormatted(fac($n-$r))," \*\[Tex \\LARGE \\textrm{_{$n}C_{$r}=\\frac{",fac($n),"}{(",fac($n-$r),")(",fac($r),")}}] Calculate ",$r,"! to get ",CommaFormatted(fac($r))," \*\[Tex \\LARGE \\textrm{_{$n}C_{$r}=\\frac{",fac($n),"}{",fac($n-$r)*fac($r),"}}] Multiply the values ",CommaFormatted(fac($n-$r))," and ",CommaFormatted(fac($r))," to get ",CommaFormatted(fac($n-$r)*fac($r))," \*\[Tex \\LARGE \\textrm{_{$n}C_{$r}=",fac($n)/(fac($n-$r)*fac($r)),"] Divide ",CommaFormatted(fac($n))," by ",CommaFormatted(fac($n-$r)*fac($r))," to get ",CommaFormatted(fac($n)/(fac($n-$r)*fac($r)))," So $n choose $r (where order does not matter) yields ",CommaFormatted(fac($n)/(fac($n-$r)*fac($r)))," unique combination", ($ncr>1)?"s":" "; } ## END NCR ==section output ==section check angle=40 angle1=50