Skip to content

Instantly share code, notes, and snippets.

@awwaiid
Created March 20, 2014 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save awwaiid/9664567 to your computer and use it in GitHub Desktop.
Save awwaiid/9664567 to your computer and use it in GitHub Desktop.
Simulate UCLA games
#!/usr/bin/env ruby
require 'csv'
require 'pp'
$season = {}
# Data from http://www.spreadsheet-sports.com/2014-ncaa-tournament-data/
CSV.foreach('2014 Game Results Data.csv', headers: true, return_headers: true) do |game|
$season[game["Team"]] ||= []<< game
$season[game["Team"]] << game
end
def play(team_a, team_b)
team_a_game_result = $season[team_a].sample["Team Result"]
team_b_game_result = $season[team_b].sample["Team Result"]
# puts "Team: #{team_a} - #{team_a_game_result}"
# pp $season[team_a]
# puts "Team: #{team_b} - #{team_b_game_result}"
# pp $season[team_b]
if team_a_game_result == "Win" && team_b_game_result == "Loss"
team_a
elsif team_a_game_result == "Loss" && team_b_game_result == "Win"
team_b
else
rand > 0.5 ? team_a : team_b
end
end
team_a = ARGV.shift
team_b = ARGV.shift
results = (0..100).map { play(team_a, team_b) }
h = Hash.new(0)
results.each { | v | h.store(v, h[v]+1) }
pp h
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment