This file contains hidden or 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
def assign_correct_santa | |
assigned = assign_random_santa | |
santa_shuffled = @santa_shuffled.clone | |
assigned.each do |person| | |
potential = assigned.select{ |other_person| person.assigned_santa.legit_santa(other_person) && | |
other_person.assigned_santa.legit_santa(person) } | |
unless potential.empty? | |
other_person = potential [ rand ] | |
to_swap = person.assigned_santa | |
person.assigned_santa = other_person.assigned_santa |
This file contains hidden or 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
class Flights | |
attr_reader :origin, :destination, :departure, :arrival, :price | |
def initialize(list) | |
@origin = list[0] | |
@destination = list[1] | |
@departure = list[2] | |
@arrival = list[3] | |
@price = list[4] |
This file contains hidden or 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
#sample data set | |
2 | |
3 | |
A,B,09:00,10:00,100.00 | |
B,Z,11:30,13:30,100.00 | |
A,Z,10:00,12:00,300.00 | |
7 |
This file contains hidden or 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
class SecretSanta | |
def initialize(find_santas) | |
@find_santas = find_santas | |
end | |
def run!(list) | |
get_list = get_people_list(list) | |
get_random_list = random_list(get_list) | |
print_error(@find_santas.get_family_members(get_list)) |
This file contains hidden or 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
class FindSantas | |
def get_family_members(santa_list) | |
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} | |
end | |
def assign_random_santa(santa_list, santa_shuffled) | |
santa_list.each do |person| |
This file contains hidden or 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
class Flight | |
attr_accessor :origin, :destination, :departure, :arrival, :price | |
def initialize(list) | |
@origin = list[0] | |
@destination = list[1] | |
@departure = list[2] | |
@arrival = list[3] | |
@price = list[4] |
This file contains hidden or 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
def get_flights(file) | |
flights_array = [] | |
csv_data = CSV.foreach(file) do |row| | |
flight = Flight.new(row) | |
flights_array << flight unless row.empty? | |
end | |
flights_array | |
end | |
def delete_whitespace(list) |
This file contains hidden or 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
def get_flights(file) | |
flights_array = [] | |
csv_data = CSV.foreach(file) do |row| | |
if row[1] != nil | |
flight = Flight.new(row) | |
flights_array << flight | |
elsif row.empty? | |
flights_array << row | |
end | |
end |
This file contains hidden or 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
def get_block(original_file) | |
flights_block = [] | |
original_file.each do |flight| | |
flights_block << flight | |
break if flight == [] | |
end | |
flights_block | |
end |
This file contains hidden or 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
def pick_for_jen(direct_flight_pick, indirect_flight_duration, indirect_flight) | |
if direct_flight_pick == [] | |
indirect_flight | |
elsif direct_flight_pick.get_duration <= indirect_flight_duration | |
direct_flight_pick | |
else | |
indirect_flight | |
end | |
end |