Last active
December 20, 2015 22:49
-
-
Save aselder/6208328 to your computer and use it in GitHub Desktop.
Calculate the number of suspensions a player receives in an IBL season
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CHANCE_OF_WILD_PLAY = 0.011 | |
CHANCE_OF_TEST_ON_WP = 0.015 | |
CHANCE_TO_FAIL = 0.70 | |
PAS_PER_GAME = (76..90) | |
SUSPENSION = { 1 => 50, 2 => 100, 3 => 100} | |
NUM_RUNS = 50000 | |
def fail_game(pas) | |
(1..pas).any? {|pa_num| rand < (CHANCE_OF_WILD_PLAY * CHANCE_OF_TEST_ON_WP * CHANCE_TO_FAIL)} | |
end | |
def run_season(pas) | |
game_num = 1 | |
num_fails = 0 | |
while (game_num <= 162) | |
if fail_game(pas) | |
num_fails += 1 | |
game_num += SUSPENSION[num_fails] | |
end | |
game_num += 1 | |
end | |
num_fails | |
end | |
overall_results = {} | |
PAS_PER_GAME.each do |pa| | |
results = Hash.new {|hash,k| hash[k] = 0} | |
NUM_RUNS.times do | |
results[run_season(pa)] += 1 | |
end | |
overall_results[pa] = results | |
expected_games_missed = (results[1] * 50 + results[2] * 150 + results[3] * 250) / NUM_RUNS.to_f | |
puts "#{pa}: #{results} => #{expected_games_missed}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment