$n = 16 # number of teams # number of games in given round (eg, 1st round has n/2 games) def ngr(r) return 0 if r == 0 return $n/2**r end # number of games in all previous rounds def ngp(r) return 0 if r <= 1 return ngr(r-1) + ngp(r-1) end # get game number, given team number and round number def ggn(t, r) return ((0.0+t)/2**r).ceil + ngp(r) end class InitializeController < ApplicationController def index # create the team list for team_name in ["Florida", "Butler", "Oregon", "U.N.L.V"] team = Team.new(:name => team_name, :conference => "midwest") team.save end for team_name in ["Kansas", "So. Illinois", "Pittsburgh", "U.C.L.A."] team = Team.new(:name => team_name, :conference => "west") team.save end for team_name in ["North Carolina", "U.S.C", "Vanderbilt", "Georgetown"] team = Team.new(:name => team_name, :conference => "east") team.save end for team_name in ["Ohio State", "Tennessee", "Texas A&M", "Memphis"] team = Team.new(:name => team_name, :conference => "south") team.save end # create the market list teams = Team.find_all for team in 1..$n for round in 1..((Math.log($n)/Math.log(2))).ceil market = Market.new market.team = teams[team-1] market.round = round market.game = ggn(team, round) market.outstanding_shares = 0 market.volume = 0 market.price = 0.5 market.save end end # compute opening prices set_prices redirect_to :controller => :main end end