Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 48 lines (32 sloc) 1.04 KB
#!/usr/bin/env python
import sys
def find_next_item(items, min_weight):
lowest_sku = None
lowest_rate = sys.maxint
for item in items:
rate = float(items[item]['cost']) / float(min(min_weight, items[item]['weight']))
if rate < lowest_rate:
lowest_rate = rate
lowest_sku = item
return items[lowest_sku]
def main():
file = open(sys.argv[1])
min_weight = int(file.readline())
items = {}
for line in file:
line_split = line.split()
sku = line_split[0]
item_details = {}
item_details['sku'] = line_split[0]
item_details['weight'] = int(line_split[1])
item_details['cost'] = int(line_split[2])
items[sku] = item_details
file.close()
total_cost = 0
while(min_weight > 0):
item = find_next_item(items, min_weight)
total_cost += item['cost']
min_weight -= item['weight']
print(total_cost)
if __name__ == "__main__":
main()