# Let's make a nice class class Team attr_reader :description def initialize(p1 = "Player 1", p2 = "Player 2", desc = "Desc") @player1 = p1 @player2 = p2 @description = desc @attributes = Hash.new end def printAttrib @attributes.each { |attrib, value| puts "#{attrib}: #{value}" } end def setAttrib(attribName, dVal) if @attributes[attribName] == nil @attributes[attribName] = 0 end @attributes[attribName] += dVal end def getAttribVal(attribNAme) if @attributes[attribName] == nil return 0 else return @attributes[attribName] end end def getScore @total = 0 @attributes.each { |key, val| @total += val } return @total end end # Program # Read in the stuff rankings = IO.readlines("rankings.txt") teamLines = IO.readlines("teams.txt") teams = Array.new # Create the team objects 12.times { |num| @teamname = teamLines[num * 3].strip @names = teamLines[num * 3 + 1] .strip @members = @names.split(" & ") temp = Team.new(@members[0], @members[1], @teamname) teams.push(temp) } # Read in and assign attributes and points attributes = ["Whininess", "Compatibility", "Appearence", "Sarcasm", "Navigation", "Athleticism", "Sneakiness"] attribute = 0 rankings.each { |line| count = 0 vals = line.split("\t") vals.each { |val| teams[count].setAttrib(attributes[attribute], val.to_i) count += 1 } attribute += 1 } # Sort the teams by the most points teams = teams.sort { |a, b| b.getScore <=> a.getScore } teams.each { |team| puts "#{team.description} with a score of #{team.getScore}" } puts "\n[Eliminations]\n\n" count = 1 # Print teams in order of elimination teams.reverse.each { |team| puts "#{team.description} will be eliminated on Leg #{count}" count += 1 }