Last active
September 2, 2016 19:55
-
-
Save hjhart/40026673d43addb7f776 to your computer and use it in GitHub Desktop.
This file contains 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
recipients = ['james', 'stephanie', 'lauren', 'james k', 'brittany', 'lyrica', 'dad', 'mom'] | |
senders = recipients.dup | |
results = recipients.map do |recipient| | |
sender = senders.sample | |
while(sender == recipient) | |
sender = senders.sample | |
end | |
senders.delete(sender) | |
[recipient, sender] | |
end | |
results.each { |result| puts result[0] => result[1] } |
Result:
{"james"=>"dad"}
{"stephanie"=>"lauren"}
{"lauren"=>"brittany"}
{"james k"=>"mom"}
{"brittany"=>"james"}
{"lyrica"=>"stephanie"}
{"dad"=>"james k"}
{"mom"=>"lyrica"}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Result:
[["james", "stephanie"], ["stephanie", "mom"], ["lauren", "james"], ["james k", "dad"], ["brittany", "lyrica"], ["lyrica", "brittany"], ["dad", "james k"], ["mom", "lauren"]]
James => Stephanie
Stephanie => Mom
Lauren => James
James K => Dad
Brittany => Lyrica
Lyrica => Brittany
Dad => James K
Mom => Lauren