public
Created

$ secret_santa.rb billy timmy jimmy molly mary julie anne

  • Download Gist
secret_santa.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
#!/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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.