Skip to content

Instantly share code, notes, and snippets.

@JoshuaEstes
Last active December 10, 2015 19:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JoshuaEstes/4480815 to your computer and use it in GitHub Desktop.
Save JoshuaEstes/4480815 to your computer and use it in GitHub Desktop.
PHP Math functions =D
<?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