-
-
Save leohmoraes/8592399ff3fafffcb92aaeebbfd3f21f to your computer and use it in GitHub Desktop.
Secret santa script for christmas
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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