Last active
December 10, 2015 19:19
-
-
Save JoshuaEstes/4480815 to your computer and use it in GitHub Desktop.
PHP Math functions =D
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Computes the factorial of $n | |
* @param interger $n Number you want to find the factorial for | |
* @return string | |
*/ | |
$factorial = function($n) { | |
for($k=1, $i=1;$i <= $n;$i++) { | |
$k = $k * $i; | |
} | |
// convert | |
$k = sprintf('%f',$k); | |
// return the number only | |
return substr($k, strpos($k, '.'), 0); | |
}; | |
/** | |
* Returns the number of combinations | |
* @param integer $x Total numbers | |
* @param integer $y Total choosen | |
* @return string | |
*/ | |
$combin = function($x,$y) use($factorial) | |
{ | |
return $factorial($x)/($factorial($y)*$factorial($x-$y)); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment