Skip to content

Instantly share code, notes, and snippets.

View pumpkincouture's full-sized avatar

Sylwia Bridges pumpkincouture

View GitHub Profile
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
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]
#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
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))
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|
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]
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)
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
def get_block(original_file)
flights_block = []
original_file.each do |flight|
flights_block << flight
break if flight == []
end
flights_block
end
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