Skip to content

@hyperbolist /secret_santa.rb
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
$ 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
Something went wrong with that request. Please try again.