changeset 5:cd24a8027d5f draft

parseinput: skip impossible and unprofitable machines
author Jordi Gutiérrez Hermoso <jordigh@octave.org>
date Wed, 11 Mar 2015 10:30:15 -0400
parents 14c8b6dad88a
children d4be13772b01
files optim.py
diffstat 1 files changed, 8 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/optim.py
+++ b/optim.py
@@ -20,9 +20,17 @@
             for i in range(0, N):
                 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)
+
+                # Skip machines that can only give a loss. This
+                # includes machines that can only be bought after
+                # case.days.
+                if maxprofit < 0:
+                    continue
+
                 machine = machine._replace(maxprofit = maxprofit)
                 case.machines.append(machine)