Skip to content

Instantly share code, notes, and snippets.

@ddelponte
Created January 17, 2013 13:10
Show Gist options
  • Save ddelponte/4555839 to your computer and use it in GitHub Desktop.
Save ddelponte/4555839 to your computer and use it in GitHub Desktop.
Secret Santa
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