Created
January 17, 2013 13:10
-
-
Save ddelponte/4555839 to your computer and use it in GitHub Desktop.
Secret Santa
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
public Map generateAssignments(List<String> participants) { | |
def assignees = participants.clone() | |
Collections.shuffle(participants) | |
Collections.shuffle(assignees) | |
def assignments = [:] | |
participants.each { participant -> | |
def assignee = assignees.find{ it != participant} | |
assignments[assignee] = participant | |
assignees = assignees - assignee | |
} | |
return assignments | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment