note 101726 deleted from function.gmp-fact by danbrown
| From: | danbrown@php.net | Date: | Fri, 07 Jan 2011 17:26:42 +0000 |
| Subject: | note 101726 deleted from function.gmp-fact by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-175517@lists.php.net to get a copy of this message | ||
Note Submitter: jbboehr at gmail dot com
----
Here's a short, lazy version of ghsot's function (with support for "division" of
factorials), and a function that calculates number of permutations:
<?php
function factorial($n, $b = 1) {
$v = 1;
do { $v *= $n; } while( --$n > $b );
return $v;
}
function permutations($n, $k = 2)
{
if( $n < $k ) return false;
return factorial($n, $n - $k);
}