changeset 3:c683f80bc858 draft

parseinput: also save the maximum possible profit for each machine
author Jordi Gutiérrez Hermoso <jordigh@octave.org>
date Tue, 10 Mar 2015 21:17:54 -0400
parents 3632502b8af1
children 14c8b6dad88a
files optim.py
diffstat 1 files changed, 8 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/optim.py
+++ b/optim.py
@@ -2,7 +2,7 @@
 
 from collections import namedtuple
 
-Machine = namedtuple("Machine", ["day", "buy", "sell", "profit"])
+Machine = namedtuple("Machine", ["day", "buy", "sell", "profit", "maxprofit"])
 Case = namedtuple("Case", ["machines", "days", "capital"])
 
 def parseinput(fname):
@@ -18,8 +18,14 @@
             N = header[0]
             case = Case([], header[1], header[2])
             for i in range(0, N):
-                machine = Machine(*[int(x) for x in f.readline().split()])
+                machine = Machine(*[int(x) for x in f.readline().split()],
+                                  maxprofit = None)
+                # Maximum profit possible from each machine
+                maxprofit = ((case.days - machine.day)*machine.profit
+                             - machine.buy + machine.sell)
+                machine = machine._replace(maxprofit = maxprofit)
                 case.machines.append(machine)
+
             cases.append(case)
 
 def main():