Skip to content

Instantly share code, notes, and snippets.

@quad
Created August 10, 2012 05:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save quad/3311466 to your computer and use it in GitHub Desktop.
Save quad/3311466 to your computer and use it in GitHub Desktop.
Discrimination made easy!
NUM_POOLS = 5
Grad = Struct.new :name, :gender, :region
def norm_name first, last
"#{first.strip} #{last.strip}"
end
def norm_gender gender
{'M' => 'Male', 'F' => 'Female'}[gender] || gender
end
def norm_region region
region
end
def sort_hashes(hashes, keys)
hashes.sort do |a, b|
a_keys = keys.map { |k| a.members.index k.to_s }
b_keys = keys.map { |k| b.members.index k.to_s }
a.values_at(*a_keys) <=> b.values_at(*b_keys)
end
end
grads = $<.map do |l|
name_first, name_last, gender, region, office, role, email_p, email_tw, phone, coach, team = l.split("\t")
Grad.new norm_name(name_first, name_last), norm_gender(gender), norm_region(region)
end.shuffle
puts sort_hashes(grads, [:gender, :region]) \
.each_with_index \
.group_by { |o, i| i % NUM_POOLS } \
.values \
.map { |pool| pool.shuffle.map { |g, i| g.name }.join "\n" } \
.join "\n\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment