Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?
- function nextRow(array $row, $size) {
- $newRow = array();
- $step = 0;
- do {
- $rowSum = 0;
- for($i = 0; $i > -$size; $i--) {
- $rowSum += $row[$i+$step];
- }
- if($rowSum > 0) {
- $newRow[$step] = $rowSum;
- }
- $step++;
- } while($rowSum > 0);
- return $newRow;
- }
- function rowCDF(array $row, $n, $m, $min = 0, $max = 0, $adj = 0) {
- $total = pow($m, $n);
- if($min == 0) { $min = $n; }
- if($max == 0) { $max = $m * $n; }
- $adj++;
- $min -= $n * $adj;
- $max -= $n * $adj;
- for(; $min <= $max; $min++) {
- $sum += $row[$min];
- }
- return $sum / $total;
- }
- $g = (object)$_GET;
- $row = array(1);
- $n = (int)$g->n;
- $m = (int)$g->m;
- while($n) {
- $row = nextRow($row, $m);
- $n--;
- }
- $prob = rowCDF($row, (int)$g->n, $m, (int)$g->min, (int)$g->max, (int)$g->adj);
- echo $prob;
Add Comment
Please, Sign In to add comment