Skip to content

Instantly share code, notes, and snippets.

@Ethan826
Last active August 9, 2016 04:17
Show Gist options
  • Save Ethan826/65a948e624a697af8f976bb1218be02e to your computer and use it in GitHub Desktop.
Save Ethan826/65a948e624a697af8f976bb1218be02e to your computer and use it in GitHub Desktop.
class Odds
def initialize
@teams = {ari: 1998, atl: 1871, bal: 1901, bos: 1901, chc: 1874, cws: 1901,
cin: 1882, cle: 1901, col: 1993, det: 1901, fla: 1993, hou: 1962,
kan: 1969, laa: 1961, lad: 1884, mil: 1969, min: 1901, nym: 1962,
nyy: 1901, oak: 1901, phi: 1883, pit: 1882, sd: 1969, sea: 1977,
sf: 1883, stl: 1882, tb: 1998, tex: 1961, tor: 1977, was: 1969}
end
def tally_teams_given_year(year)
@teams.values.select { |y| y <= year }.count
end
def probability_of_losing_between_years(begin_year, end_year)
(begin_year..end_year).reduce(1.0) do |accum, el|
tally = tally_teams_given_year(el)
tally > 1 ? accum * ((tally - 1.0) / tally) : accum
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment