Mercurial > hg > problem6
comparison optim.py @ 6:d4be13772b01 draft
final_capital: consider as invalid plans that buy more than one machine per day
author | Jordi Gutiérrez Hermoso <jordigh@octave.org> |
---|---|
date | Tue, 10 Mar 2015 22:20:59 -0400 |
parents | cd24a8027d5f |
children | af2598b58791 |
comparison
equal
deleted
inserted
replaced
5:cd24a8027d5f | 6:d4be13772b01 |
---|---|
64 "machine cost is %d, and capital is %d" | 64 "machine cost is %d, and capital is %d" |
65 % (machine.day, machine.buy, capital)) | 65 % (machine.day, machine.buy, capital)) |
66 | 66 |
67 capital -= machine.buy | 67 capital -= machine.buy |
68 if slot: | 68 if slot: |
69 if machine.day == slot.day: | |
70 raise InvalidPlan("Cannot buy two machines on the same day: %d" | |
71 % (machine.day)) | |
72 | |
69 # Subtract 1, because the machine in the slot cannot | 73 # Subtract 1, because the machine in the slot cannot |
70 # be used the day it's sold. | 74 # be used the day it's sold. |
71 days_used = machine.day - slot.day - 1 | 75 days_used = machine.day - slot.day - 1 |
72 capital += days_used*slot.profit | 76 capital += days_used*slot.profit |
73 capital += slot.sell | 77 capital += slot.sell |