Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function test($current, $n, $type = 1)
- {
- $balls = [[65, 1], [75, 3], [85, 5], [0, 0]];
- list($prob, $cost) = $balls[$type];
- $price = 0;
- while ($current < $n) {
- if ($type == 3) {
- list($prob, $cost) = $current < 12 ? $balls[0] : $balls[2];
- }
- $success = rand(1, 100) <= $prob;
- if ($success) {
- $current++;
- } else {
- $current -= floor($current / 4);
- }
- $price += $cost;
- }
- return $price;
- }
- $h = fopen('out.csv', 'w');
- $cnt = 1000000;
- for ($from = 0; $from < 30; $from++) {
- $current = [];
- for ($type = 0; $type < 4; $type++) {
- if ($from > 15 && $type < 3) {
- continue;
- }
- $avg = 0;
- for ($i = 1; $i < $cnt; $i++) {
- $avg = $avg * ($i - 1) / $i + test($from, $from + 1, $type) / $i;
- }
- $current[$type] = $avg;
- }
- fputcsv($h, [
- 'f' => $from + 1,
- 'w' => $current[0] ?? 0,
- 'b' => $current[1] ?? 0,
- 'r' => $current[2] ?? 0,
- 'o' => $current[3] ?? 0,
- ]);
- echo $from, PHP_EOL;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement