Skip to content

Instantly share code, notes, and snippets.

@leohmoraes
Forked from gacha/secret-santa.rb
Created December 8, 2021 00:34
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 leohmoraes/8592399ff3fafffcb92aaeebbfd3f21f to your computer and use it in GitHub Desktop.
Save leohmoraes/8592399ff3fafffcb92aaeebbfd3f21f 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