本文整理汇总了PHP中factorial函数的典型用法代码示例。如果您正苦于以下问题:PHP factorial函数的具体用法?PHP factorial怎么用?PHP factorial使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了factorial函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: factorial
function factorial($x)
{
if (0 == $x) {
return 1;
}
return $x * factorial($x - 1);
}
开发者ID:renanbr,项目名称:telltale,代码行数:7,代码来源:basic.php
示例2: factorial
function factorial($i)
{
if ($i <= 1) {
return 1;
}
return $i * factorial($i - 1);
}
开发者ID:rodtejedor,项目名称:vcalc,代码行数:7,代码来源:vcalc.php
示例3: factorial
function factorial($n)
{
if ($n < 2) {
return $n;
}
return $n * factorial($n - 1);
}
开发者ID:soft-age,项目名称:learn-php,代码行数:7,代码来源:factorial.php
示例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);
}
开发者ID:ronanmcdonnell,项目名称:PHP-Permutations,代码行数:27,代码来源:randomise.php
示例5: factorial
function factorial($x)
{
if ($x <= 1) {
return TRUE;
}
return $x * factorial($x - 1);
}
开发者ID:turjoy,项目名称:php,代码行数:7,代码来源:factorial-with-recursive-function.php
示例6: factorial
function factorial($n)
{
if ($n == 1) {
return 1;
}
return $n * factorial($n - 1);
}
开发者ID:CelesteSuarez,项目名称:hackathon-IBM,代码行数:7,代码来源:subir.php
示例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);
}
开发者ID:adhocore,项目名称:dsa,代码行数:16,代码来源:factorial.php
示例8: factorial
function factorial($number)
{
if ($number === 1) {
return $number;
}
return factorial($number - 1) * $number;
}
开发者ID:YuraMalahov,项目名称:algorithms,代码行数:7,代码来源:factorial.php
示例9: factorial
function factorial($n)
{
if ($n == 0) {
return 1;
}
return factorial($n - 1) * $n;
}
开发者ID:raynaldmo,项目名称:php-education,代码行数:7,代码来源:exercise2.php
示例10: createResultArray
function createResultArray($ro, $steps)
{
$resultArray = array();
for ($k = 0; $k < $steps; $k++) {
$resultArray[] = pow($ro, $k) * exp(-$ro) / factorial($k);
}
return $resultArray;
}
开发者ID:Aleksej-Shherbak,项目名称:MMPIiS,代码行数:8,代码来源:lib.inc.php
示例11: calc
function calc($n)
{
$res = 0;
for ($i = 0; $i <= $n; $i++) {
$res += 1 / factorial($i);
}
return $res;
}
开发者ID:spookey,项目名称:euler,代码行数:8,代码来源:main.php
示例12: factorial
function factorial($num)
{
if ($num == 1) {
return 1;
}
echo $num . "<br />";
return $num * factorial($num - 1);
}
开发者ID:skyview059,项目名称:Advanced-PHP-MySql,代码行数:8,代码来源:day_01_function.php
示例13: factorial
function factorial($n)
{
if ($n <= 1) {
return 1;
} else {
return $n * factorial($n - 1);
}
}
开发者ID:nicksteffen,项目名称:424,代码行数:8,代码来源:processform.php
示例14: factorial
function factorial($x)
{
if ($x <= 1) {
return 1;
} else {
return $x * factorial($x - 1);
}
}
开发者ID:cosim,项目名称:fuzuli,代码行数:8,代码来源:factorial.php
示例15: factorial
/**
* @param int $number
*/
function factorial($number)
{
if ($number < 2) {
return 1;
} else {
return factorial($number - 1) * $number;
}
}
开发者ID:iolevel,项目名称:peachpie,代码行数:11,代码来源:factorial.php
示例16: factorial
function factorial($x)
{
static $cache = [];
if (isset($cache[$x])) {
return $cache[$x];
}
$cache[$x] = $x == 1 ? 1 : $x * factorial($x - 1);
return $cache[$x];
}
开发者ID:zmwebdev,项目名称:PHPcookbook-code-3ed,代码行数:9,代码来源:factorial2.php
示例17: factorial
function factorial($x)
{
assert(gettype($x) == "integer");
if ($x == 1) {
return 1;
} else {
return $x * factorial($x - 1);
}
}
开发者ID:makihiro,项目名称:blog_post,代码行数:9,代码来源:sample.php
示例18: factorial
/**
* @param $number
*
* @return int
*/
function factorial($number)
{
if ($number < 2) {
return 1;
} else {
echo $number . '*' . $number - 1;
return $number * factorial($number - 1);
}
}
开发者ID:biroa,项目名称:php_algorithms,代码行数:14,代码来源:factorial.php
示例19: factorial
function factorial($numb)
{
if ($numb > 1) {
return $numb * factorial($numb - 1);
}
if ($numb < 0) {
return -1;
}
return 1;
}
开发者ID:Nisaiy,项目名称:DeveloperClub,代码行数:10,代码来源:factorial.php
示例20: factorial
/**
* <em>Calculating factorial for a given number</em>
*
* @param int $num an integer of a value to be calculated
* @return int $result a final factorial result
*/
function factorial($num)
{
if ($num == 0) {
return 1;
} else {
$result = $num * factorial($num - 1);
//Using recursive function.
}
return $result;
}
开发者ID:rluena,项目名称:mycoderbyte,代码行数:16,代码来源:2_factorial.php
注:本文中的factorial函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论