Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2015
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. def secret_santa_game
  2.  
  3. givers = ["Luke Skywalker luke@theforce.net",
  4. "Leia Skywalker leia@therebellion.org",
  5. "Toula Portokalos toula@manhunter.org",
  6. "Gus Portokalos gus@weareallfruit.net",
  7. "Bruce Wayne bruce@imbatman.com",
  8. "Virgil Brigman virgil@rigworkersunion.org",
  9. "Lindsey Brigman lindsey@iseealiens.net"]
  10.  
  11. recipients = givers.dup
  12.  
  13. pairs = []
  14.  
  15. while givers.any?
  16. recipients.shuffle!
  17. if (givers.first == recipients.last) && (givers.length > 1)
  18. next
  19. end
  20.  
  21. secret_santa = givers.shift()
  22. selected_name = recipients.pop
  23.  
  24. if secret_santa != selected_name
  25. pairs << "#{secret_santa} is the secret santa of #{selected_name}"
  26. else
  27. return :try_again
  28. end
  29. end
  30.  
  31. return pairs
  32.  
  33. end
  34.  
  35. pairs = :try_again
  36.  
  37. while pairs == :try_again
  38. pairs = secret_santa_game
  39. end
  40.  
  41. puts pairs
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement