Skip to content

Instantly share code, notes, and snippets.

@javierav
Created December 2, 2014 15:27
Show Gist options
  • Save javierav/a6acabfc7002a8f378b2 to your computer and use it in GitHub Desktop.
Save javierav/a6acabfc7002a8f378b2 to your computer and use it in GitHub Desktop.
Ruby Secret Santa
# Ruby Secret Santa
# Javier Aranda <jaranda@nosolosoftware.es>
# MIT license
# friends list
@friends = [
{ name: 'Jesús Taguas', alias: 'jtaguas' },
{ name: 'Rafa García', alias: 'rgarcia' },
{ name: 'Jesús González', alias: 'jgonzalez' },
{ name: 'Paco Hidalgo', alias: 'fhidalgo' },
{ name: 'Juan Antonio Galisteo', alias: 'jgalisteo' },
{ name: 'Alberto Galisteo', alias: 'agalisteo' },
{ name: 'Luis Ciudad', alias: 'lciudad' },
{ name: 'Javier Aranda', alias: 'jaranda' },
{ name: 'Rafael Perez', alias: 'rperez' },
{ name: 'Rafael Jurado', alias: 'rjurado' },
{ name: 'Carlos Barasona', alias: 'cbarasona' },
{ name: 'Francisco Aranda', alias: 'faranda' },
{ name: 'Juan Manuel Jurado', alias: 'jjurado' },
{ name: 'Shelma Hayoun', alias: 'shayoun' },
{ name: 'Teresa Prieto', alias: 'tprieto' },
{ name: 'Pedro Navajas', alias: 'pnavajas' },
{ name: 'Francisco Vena', alias: 'fvena' }
]
@max = @friends.count
# already selected friends
@selected_for_give_present = []
@selected_for_receive_present = []
@giver = nil
@receiver = nil
loop do
break if @selected_for_give_present.count == @max
# select available giver
loop do
@giver = Random.rand(@max)
break if not @selected_for_give_present.include? @giver
end
# select available receiver
loop do
@receiver = Random.rand(@max)
break if not @selected_for_receive_present.include? @receiver and @giver != @receiver
end
# notify pair
puts "#{@friends[@giver - 1][:name]} (giver) => #{@friends[@receiver - 1][:name]} (receiver)"
# TODO: remove puts and notify by email (givers only)
# adds pair to selected arrays
@selected_for_give_present << @giver
@selected_for_receive_present << @receiver
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment