Advertisement
Guest User

Untitled

a guest
Jan 24th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.15 KB | None | 0 0
  1. function test($current, $n, $type = 1)
  2. {
  3.     $balls = [[65, 1], [75, 3], [85, 5], [0, 0]];
  4.  
  5.     list($prob, $cost) = $balls[$type];
  6.  
  7.     $price = 0;
  8.     while ($current < $n) {
  9.         if ($type == 3) {
  10.             list($prob, $cost) = $current < 12 ? $balls[0] : $balls[2];
  11.         }
  12.         $success = rand(1, 100) <= $prob;
  13.         if ($success) {
  14.             $current++;
  15.         } else {
  16.             $current -= floor($current / 4);
  17.         }
  18.         $price += $cost;
  19.     }
  20.     return $price;
  21. }
  22.  
  23. $h = fopen('out.csv', 'w');
  24. $cnt = 1000000;
  25.  
  26. for ($from = 0; $from < 30; $from++) {
  27.  
  28.     $current = [];
  29.  
  30.     for ($type = 0; $type < 4; $type++) {
  31.  
  32.         if ($from > 15 && $type < 3) {
  33.             continue;
  34.         }
  35.  
  36.         $avg = 0;
  37.  
  38.         for ($i = 1; $i < $cnt; $i++) {
  39.             $avg = $avg * ($i - 1) / $i + test($from, $from + 1, $type) / $i;
  40.         }
  41.         $current[$type] = $avg;
  42.  
  43.     }
  44.  
  45.     fputcsv($h, [
  46.         'f' => $from + 1,
  47.         'w' => $current[0] ?? 0,
  48.         'b' => $current[1] ?? 0,
  49.         'r' => $current[2] ?? 0,
  50.         'o' => $current[3] ?? 0,
  51.     ]);
  52.  
  53.     echo $from, PHP_EOL;
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement