本文整理汇总了PHP中factorial函数的典型用法代码示例。如果您正苦于以下问题:PHP factorial函数的具体用法?PHP factorial怎么用?PHP factorial使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了factorial函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: factorial
function factorial($x)
{
if (0 == $x) {
return 1;
}
return $x * factorial($x - 1);
}
示例2: factorial
function factorial($i)
{
if ($i <= 1) {
return 1;
}
return $i * factorial($i - 1);
}
示例3: factorial
function factorial($n)
{
if ($n < 2) {
return $n;
}
return $n * factorial($n - 1);
}
示例4: getAllPermutations
function getAllPermutations($numberOfChosenElements, $setSize)
{
//r = number of Chosen Elements
//n = set Size
//number of Combinations = n!/((n-r)!(r!))
//returns an array of combinations
$n = intval($setSize);
$r = intval($numberOfChosenElements);
//calculate total combinations (inc. non unique)
$totalCombinations = factorial($setSize);
//unique combinations
$uniqueCombinations = factorial($n) / (factorial($n - $r) * factorial($r));
//permutations = (number of Chosen Elements)^ set Size
$permutations = pow($n, $r);
$array = array();
//$uniqueList = array();
//echo "Total Combinations: " . $totalCombinations . "<br/>";
echo "Permutations: " . $permutations . "<br/>";
$i = 0;
for ($i = 0; $i < $r; $i++) {
//initialize array to all 0's
$array[$i] = 0;
}
$i = 0;
//start combo checking!
Permutation(0, $array, $n);
}
示例5: factorial
function factorial($x)
{
if ($x <= 1) {
return TRUE;
}
return $x * factorial($x - 1);
}
示例6: factorial
function factorial($n)
{
if ($n == 1) {
return 1;
}
return $n * factorial($n - 1);
}
示例7: factorial
/**
* factorial.
*
* @param int $n The number to calculate factorial for
*
* @return int The factorial of $n
*
* @throws InvalidArgumentException If input is not valid number
*/
function factorial($n)
{
if (!is_numeric($n)) {
throw new \InvalidArgumentException(sprintf('%s is not valid number', $n));
}
return $n < 2 ? 1 : $n * factorial($n - 1);
}
示例8: factorial
function factorial($number)
{
if ($number === 1) {
return $number;
}
return factorial($number - 1) * $number;
}
示例9: factorial
function factorial($n)
{
if ($n == 0) {
return 1;
}
return factorial($n - 1) * $n;
}
示例10: createResultArray
function createResultArray($ro, $steps)
{
$resultArray = array();
for ($k = 0; $k < $steps; $k++) {
$resultArray[] = pow($ro, $k) * exp(-$ro) / factorial($k);
}
return $resultArray;
}
示例11: calc
function calc($n)
{
$res = 0;
for ($i = 0; $i <= $n; $i++) {
$res += 1 / factorial($i);
}
return $res;
}
示例12: factorial
function factorial($num)
{
if ($num == 1) {
return 1;
}
echo $num . "<br />";
return $num * factorial($num - 1);
}
示例13: factorial
function factorial($n)
{
if ($n <= 1) {
return 1;
} else {
return $n * factorial($n - 1);
}
}
示例14: factorial
function factorial($x)
{
if ($x <= 1) {
return 1;
} else {
return $x * factorial($x - 1);
}
}
示例15: factorial
/**
* @param int $number
*/
function factorial($number)
{
if ($number < 2) {
return 1;
} else {
return factorial($number - 1) * $number;
}
}