class math_functions {
public function factorial($num,$y = 1) {
for ($i=1;$i <= $num;$i++) {
$y *= $i;
}
return $y;
}
public function permutation($n,$r) {
$result = ($this->factorial($n) / $this->factorial($n-$r));
return $result;
}
public function combination($n,$r) {
$result = ($this->factorial($n) / ($this->factorial($n-$r) * $this->factorial($r)));
return $result;
}
public function average($nums,$total=0) {
if (is_array($nums)) {
$count = count($nums);
for ($i=0;$i <= $count;$i++) {
$total += $i;
}
}
return ($total / $count);
}
public function get_base($num,$us,$y=1) {
if ($us == 0) {
return 1;
} else {
for ($i=1;$i <= $us;$i++) {
$y *= $num;
}
}
return $y;
}
public function gauss($n) {
$result = ($n * ($n + 1) / 2);
return $result;
}
public function fibonacci($i) {
$at = array();
for ($j = 1;$j <= $i;$j++) {
if ($j == 1) {
$at[] = 1;
} else {
$ct = count($at)-1;
$sn = $at[$ct];
$snd = ($ct-1 > -1) ? $snd = $at[$ct-1] : $snd = 0;
$at[] = $sn+$snd;
}
}
print_r($at);
}
}