Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ランダムに2チームへ分けるスクリプト グッパでホイ編
#!/usr/bin/env ruby
class Member
attr_reader :name
def initialize(name)
@name = name
end
def hand
[ :gu, :pa ].sample
end
end
if $0 == __FILE__
srand(Time.local(2012, 9, 6).to_i)
members = ARGF.map do |name|
Member.new(name.chomp)
end
begin
teams = members.group_by do |member|
member.hand
end
end until teams[:gu].size == members.count / 2
puts "Gu: #{teams[:gu].map {|member| member.name }.join(' ')}"
puts "Pa: #{teams[:pa].map {|member| member.name }.join(' ')}"
end
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.