Created
February 19, 2014 19:40
-
-
Save dgreenbe77/9099942 to your computer and use it in GitHub Desktop.
Crazy_Arrayz_Arrayz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'pry' | |
| #Command line: Prompt user to input one teammember name at a time, until they are done. | |
| name_array = [] | |
| loop do | |
| print "Enter a name. Type 'done' when finished. " | |
| name = gets.chomp | |
| break if name=='done' | |
| name_array << name | |
| end | |
| #Ask how many sets of pairs user wants to generate. | |
| #pairing_num | |
| puts "For how many days would you like to generate pairs?" | |
| days_wanted = gets.chomp.to_i | |
| #Generate and print out sets of pairs. | |
| len = name_array.length | |
| day_pairs_array = Array.new | |
| days_wanted.times do | |
| name_array_copy = name_array.dup.shuffle | |
| pairs_array = [] | |
| (len/2).times do | |
| pairs_array << name_array_copy.pop(2) | |
| end | |
| day_pairs_array.push(pairs_array) | |
| end | |
| # day_pairs = [ | |
| # [ | |
| # ['nick', 'john'], | |
| # ['tom', 'bill'] | |
| # ], | |
| # [ | |
| # ['bill', 'john'], | |
| # ['nick', 'tom'] | |
| # ] | |
| # ] | |
| # ] | |
| day_pairs_array.each_with_index do |day, index| | |
| puts "Day #{index + 1}" | |
| print day | |
| puts | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment