Guest User

Untitled

a guest
Jun 19th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. <?
  2.  
  3. function nextRow(array $row, $size) {
  4. $newRow = array();
  5.  
  6. $step = 0;
  7. do {
  8. $rowSum = 0;
  9. for($i = 0; $i > -$size; $i--) {
  10. $rowSum += $row[$i+$step];
  11. }
  12. if($rowSum > 0) {
  13. $newRow[$step] = $rowSum;
  14. }
  15.  
  16. $step++;
  17.  
  18. } while($rowSum > 0);
  19. return $newRow;
  20. }
  21.  
  22.  
  23. function rowCDF(array $row, $n, $m, $min = 0, $max = 0, $adj = 0) {
  24. $total = pow($m, $n);
  25. if($min == 0) { $min = $n; }
  26. if($max == 0) { $max = $m * $n; }
  27. $adj++;
  28. $min -= $n * $adj;
  29. $max -= $n * $adj;
  30. for(; $min <= $max; $min++) {
  31. $sum += $row[$min];
  32. }
  33. return $sum / $total;
  34. }
  35.  
  36. $g = (object)$_GET;
  37.  
  38. $row = array(1);
  39. $n = (int)$g->n;
  40. $m = (int)$g->m;
  41.  
  42. while($n) {
  43. $row = nextRow($row, $m);
  44. $n--;
  45. }
  46.  
  47. $prob = rowCDF($row, (int)$g->n, $m, (int)$g->min, (int)$g->max, (int)$g->adj);
  48. echo $prob;
Add Comment
Please, Sign In to add comment