Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def secret_santa_game
- givers = ["Luke Skywalker luke@theforce.net",
- "Leia Skywalker leia@therebellion.org",
- "Toula Portokalos toula@manhunter.org",
- "Gus Portokalos gus@weareallfruit.net",
- "Bruce Wayne bruce@imbatman.com",
- "Virgil Brigman virgil@rigworkersunion.org",
- "Lindsey Brigman lindsey@iseealiens.net"]
- recipients = givers.dup
- pairs = []
- while givers.any?
- recipients.shuffle!
- if (givers.first == recipients.last) && (givers.length > 1)
- next
- end
- secret_santa = givers.shift()
- selected_name = recipients.pop
- if secret_santa != selected_name
- pairs << "#{secret_santa} is the secret santa of #{selected_name}"
- else
- return :try_again
- end
- end
- return pairs
- end
- pairs = :try_again
- while pairs == :try_again
- pairs = secret_santa_game
- end
- puts pairs
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement