Skip to content

Instantly share code, notes, and snippets.

@fenelon
Last active December 14, 2017 10:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fenelon/adad894a1fe28bb40fe9067d964ef1ac to your computer and use it in GitHub Desktop.
Save fenelon/adad894a1fe28bb40fe9067d964ef1ac to your computer and use it in GitHub Desktop.
class SecretSanta
attr_reader :pairs
def initialize(filename)
@data = File.read(filename)
@list = @data.split("\r\n").map{|s| s.split("\t")}
end
def pick
@pairs = []
@rcpt_list = @list.shuffle
@list.each do |person|
while person == (candidate = @rcpt_list.sample)
next
end
@rcpt_list.delete(candidate)
@pairs << [person, candidate]
end
print_list
return @pairs
end
def print_list
@pairs.each do |p|
puts "#{p[0][0]};#{p[0][1]};#{p[1][0]};#{p[1][1]}"
puts "\n"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment