Skip to content

Instantly share code, notes, and snippets.

@bigwheel
Created August 2, 2012 03:46
Show Gist options
  • Save bigwheel/3233153 to your computer and use it in GitHub Desktop.
Save bigwheel/3233153 to your computer and use it in GitHub Desktop.
ランダムに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