Skip to content

Instantly share code, notes, and snippets.

@hyperbolist
Created December 13, 2010 20:46
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 hyperbolist/739576 to your computer and use it in GitHub Desktop.
Save hyperbolist/739576 to your computer and use it in GitHub Desktop.
$ secret_santa.rb billy timmy jimmy molly mary julie anne
#!/usr/bin/env ruby
def pick_one(a)
a.delete_at(rand(a.size))
end
def pick_one_not(a, s)
index = rand(a.size)
return pick_one_not(a, s) if (a[index].eql?(s))
a.delete_at(index)
end
givers = []
receivers = []
ARGV.each do |name|
givers << name
receivers << name
end
(1..(givers.size)).each do
giver = pick_one(givers)
puts "#{giver} -> #{pick_one_not(receivers, giver)}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment