Skip to content

Instantly share code, notes, and snippets.

@sundevilyang
Forked from cantin/pair.rb
Created September 3, 2019 13:51
Show Gist options
  • Save sundevilyang/63df48ec1cf7ee9455afcc6a47817f97 to your computer and use it in GitHub Desktop.
Save sundevilyang/63df48ec1cf7ee9455afcc6a47817f97 to your computer and use it in GitHub Desktop.
GuangZhou RailsGirs Pair
tutors = ["***", "***", "***"]
girls = ["***", "***", "***"]
number = "To be defined"
tutors = tutors.shuffle(random: Random.new(number))
girls = girls.shuffle(random: Random.new(number))
result = Hash.new { |hash, key| hash[key] = [] }
tutors.cycle(3).each_with_index do |tutor, i|
result[tutor] << (girls[i] || "未配对")
end
result.each do |key, value|
puts "#{key} => #{value.join(", ")}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment