Skip to content

Instantly share code, notes, and snippets.

@bigwheel bigwheel/lunch.rb
Created Aug 2, 2012

Embed
What would you like to do?
ランダムに2チームへ分けるスクリプト 超人パワー編
#!/usr/bin/env ruby
srand(Time.local(2012, 8, 2).to_i)
class Member
attr_reader :name, :power
def initialize(name)
@name = name
@power = rand
end
end
members = ARGF.map do |name|
Member.new(name.chomp)
end
def members.choose!
delete_at(rand(count))
end
a_team = []
b_team = []
teams = [a_team, b_team]
while members.count != 0
if members.count == 1
teams[rand(2)] << members.choose!
break
end
red = members.choose!
blue = members.choose!
if red.power > blue.power
a_team << red
b_team << blue
else
a_team << blue
b_team << red
end
end
puts "A: #{a_team.map {|member| member.name }.join(' ')}"
puts "B: #{b_team.map {|member| member.name }.join(' ')}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.