Skip to content

Instantly share code, notes, and snippets.

@gacha
Last active December 8, 2021 00:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gacha/466a9c45e7386283f5f3 to your computer and use it in GitHub Desktop.
Save gacha/466a9c45e7386283f5f3 to your computer and use it in GitHub Desktop.
Secret santa script for christmas
#!/usr/bin/env ruby
require 'timeout'
members = %w(Gatis Jānis Anna Ilze Ieva Kaspars Juris Klāvs Pēteris)
takers = []
givers = []
exceptions = { 'Gatis' => 'Jānis'}
begin
Timeout::timeout(2) do
while members.any?
who = (members - givers).sample
to_whom = (members - takers).sample
next if who == to_whom
next if exceptions.find do |key, value|
(key == who && value == to_whom) || (key == to_whom && value == who)
end
givers << who
takers << to_whom
members.delete(who) if takers.include?(who)
members.delete(to_whom) if givers.include?(to_whom)
puts "#{who} dāvina dāvanu #{to_whom}"
end
end
rescue Timeout::Error
puts 'Nav iespējams atrast pāri, mēģini vēlreiz.'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment