forked from RealImage/challenge2019
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproblem_one.rb
32 lines (25 loc) · 851 Bytes
/
problem_one.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# frozen_string_literal: true
require './shared'
module Solution
class ProblemOne
def self.execute
partners, _capacities = Shared.initialize_csv
input = Shared.initialize_input
result = []
input.each do |input_row|
size = input_row[1]
theatre_id = input_row.last
eligible_partners = Shared.eligible_partners(partners, theatre_id, size)
if eligible_partners.any?
cheapest_partner = eligible_partners.min_by { |x| x['cost'] }
final_price = Shared.calucate_final_price(cheapest_partner, size)
result << [input_row.first, 'true', cheapest_partner['partner'], final_price]
else
result << [input_row.first, 'false', '', '']
end
end
Shared.output_csv(result, 'output1.csv')
end
end
end
Solution::ProblemOne.execute