Skip to content

Instantly share code, notes, and snippets.

@hjhart
Last active September 2, 2016 19:55
Show Gist options
  • Save hjhart/40026673d43addb7f776 to your computer and use it in GitHub Desktop.
Save hjhart/40026673d43addb7f776 to your computer and use it in GitHub Desktop.
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] }
@hjhart
Copy link
Author

hjhart commented Sep 2, 2016

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