# Altitude Sickness
edges = {
(‘A’,’B’): 10,
(‘A’,’D’): 6,
(‘A’,’C’): 7,
(‘B’,’E’): 9,
(‘C’,’E’): 7,
(‘D’,’E’): 11,
(‘D’,’F’): 7,
(‘E’,’G’): 8,
(‘E’,’H’): 7,
(‘E’,’I’): 10,
(‘F’,’G’): 8,
(‘F’,’H’): 6,
(‘F’,’I’): 7,
(‘G’,’J’): 13,
(‘H’,’J’): 8,
(‘I’,’J’): 9
}
# joe(i) gives the minimum maximum altitude from i to J
def joe(i):
if i == ‘J’:
return (0, ‘Done’)
else:
return min((max(edges[road], joe(road[1])[0]), road[1])
for road in edges if road[0] == i)
# Advertising
PH = 800
PL = 600
cA = -70 # advertising
cS = -80 # switching
# probabilities of High sales
pHY = .8
pHN = .6
pLY = .6
pLN = .2
def advertise(t,s):
if t == 5:
return (0, ‘Done’)
else:
if s == “High”:
yes = cA + pHY*(PH + advertise(t+1,’High’)[0]) + \
(1-pHY)*(PL + cS + advertise(t+1,’Low’)[0])
no = pHN*(PH + advertise(t+1,’High’)[0]) + \
(1-pHN)*(PL + cS + advertise(t+1,’Low’)[0])
else: # Low
yes = cA + pLY*(PH + cS + advertise(t+1,’High’)[0]) + \
(1-pLY)*(PL + advertise(t+1,’Low’)[0])
no = pLN*(PH + cS + advertise(t+1,’High’)[0]) + \
(1-pLN)*(PL + advertise(t+1,’Low’)[0])
return max((yes,’Yes’),(no,’No’))
for t in [1,2,3,4]:
print(“Week”,t)
print(“High:”,advertise(t,”High”))
print(“Low:”,advertise(t,”Low”))
# Strategy
# Week 1 – always advertise
# Week 2 – always advertise
# Week 3 – advertise is sales Low in Week 2
# Week 4 – never advertise