Skip to content

Instantly share code, notes, and snippets.

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