Skip to content

Instantly share code, notes, and snippets.

View pumpkincouture's full-sized avatar

Sylwia Bridges pumpkincouture

View GitHub Profile
def assign_santa(list)
pairs = []
list.each_cons(2) do |hash, next_hash|
pairs << [hash["FIRST_NAME"] + " " + hash["LAST_NAME"] + " + " + next_hash["FIRST_NAME"] + " " + next_hash["LAST_NAME"]]
end
first_name = list[0]
last_name = list[-1]
pairs << [last_name["FIRST_NAME"] + " " + last_name["LAST_NAME"] + " + " + first_name["FIRST_NAME"] + " " + first_name["LAST_NAME"]]
pairs
def refine_pairs(list)
new_sentence = []
list.each do |sub_array|
sub_array.each do |sentence|
split = sentence.split(" ")
new_sentence << split
end
end
def shuffle_list(refined_list)
random_list = refined_list.shuffle
random_array = random_list[rand]
first_name = random_array[0]
last_name = random_array[-1]
original_first = ""
original_last = ""
swap_first = ""
swap_last = ""
class Person
attr_reader :first, :last, :email
attr_accessor :assigned_santa
def initialize(list)
@first = list[0]
@last = list[1]
@email = list[2]
@assigned_santa = assigned_santa
end
class SecretSanta
attr_reader :santa_list, :santa_shuffled, :people
def initialize
@santa_list = santa_list
@santa_shuffled = santa_shuffled
@people = people
end
def people_list
def assign_random_santa
#if @santa_list.length%2 == 0
@santa_list.each do |person|
potential_partner = @santa_shuffled[ rand ]
potential = @santa_list.select{|person| person.not_self(potential_partner) && person.legit_santa(potential_partner }
# person.assigned_santa = potential_partner if person.not_self(potential_partner) && person.legit_santa(potential_partner)
# potential_partner.assigned_santa = person
person.assigned_santa = potential [ rand ] unless potential.empty?
#delete if successful assignment
# @santa_shuffled.delete(potential_partner)
def shuffle_list(matching)
duplicate_list = @santa_list.clone
# p duplicate_list
unless matching
@santa_list.each do |person|
other_combos = []
potential_partner = @santa_shuffled[ rand ]
person.assigned_santa = potential_partner
# potential_partner.select { |partner| legit_santa(person, partner) && not_self(person, partner)}
end
def how_many_families
list_length = @santa_list.length
family_members = @santa_list.group_by{|person| person.last }.values.select{|last_name| last_name.size >= list_length/2.0}
return true unless family_members.empty?
false
end
def print_error(boolean)
boolean = how_many_families
puts "Sorry, no combination exists." if boolean
def assign_random_santa
santa_shuffled = @santa_shuffled.clone
santa_list = @santa_list.clone
santa_list.each do |person|
potential_partner = santa_shuffled [ rand ]
potential = santa_shuffled.select{ |potential_person| person.legit_santa(potential_person) }
person.assigned_santa = potential [ rand ] unless potential.empty?
santa_shuffled.delete(person.assigned_santa)
end
return santa_list
def assign_random_santa
santa_shuffled = @santa_shuffled.clone
santa_list = @santa_list.clone
santa_list.each do |person|
potential_partner = santa_shuffled [ rand ]
potential = santa_shuffled.select{ |potential_person| person.not_self(potential_person) }
person.assigned_santa = potential [ rand ] unless potential.empty?
santa_shuffled.delete(person.assigned_santa)
end
santa_list