Skip to content

Instantly share code, notes, and snippets.

@juliamae
Created January 10, 2015 21:44
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 juliamae/091eca29fef10cfe5f1c to your computer and use it in GitHub Desktop.
Save juliamae/091eca29fef10cfe5f1c to your computer and use it in GitHub Desktop.
Tom Brady's career records split by mascot type
require 'csv'
require 'pp'
csv = <<-CSV
Cardinals,2,1,1,bird
Falcons,4,4,0,bird
Ravens,6,5,1,bird
Bills,26,23,3,human
Panthers,4,2,2,cat
Bears,4,4,0,"other animal"
Bengals,6,5,1,cat
Browns,6,5,1,human
Cowboys,3,3,0,human
Broncos,10,5,5,horse
Lions,5,4,1,cat
Packers,4,2,2,industry
Texans,5,4,1,human
Colts,12,9,3,horse
Jaguars,4,4,0,cat
Chiefs,6,4,2,human
Raiders,4,3,1,human
Dolphins,26,18,8,"other animal"
Vikings,4,4,0,human
Saints,4,3,1,"mythical being"
Giants,3,2,1,"mythical being"
Jets,26,20,6,industry
Eagles,3,3,0,bird
Steelers,7,5,2,industry
Chargers,7,5,2,industry
49ers,2,1,1,industry
Seahawks,2,1,1,bird
Rams,3,2,1,"other animal"
Buccaneers,3,3,0,human
Oilers,5,4,1,industry
Redskins,3,2,1,human
CSV
tallies = Hash.new([])
CSV.parse(csv) do |record|
name, total, wins, losses, mascot = record
tallies[mascot] = [(tallies[mascot][0] || 0) + wins.to_i, (tallies[mascot][1] || 0) + total.to_i]
end
results = tallies.inject({}) do |memo, record|
memo[record[0]] = record[1][0].to_f / record[1][1].to_f
memo
end
pp results.sort_by{|k,v| v}; nil
=> [["horse", 0.6363636363636364],
["mythical being", 0.7142857142857143],
["industry", 0.7254901960784313],
["other animal", 0.7272727272727273],
["cat", 0.7894736842105263],
["bird", 0.8235294117647058],
["human", 0.85]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment