Chris Pepin wrote:
> Help! I've been trying to decipher the following piece of Applesoft code for
> weeks but haven't been able to figure out what it does. My math skills are a
> bit rusty so any help is greatly appreciated. Line 1232 is especially strange
> to me. Thanks.
>
> 1190 IF P(I) > = P9 THEN 1220
>
> 1200 N1 = (P9 - P(I)) / P9 * .8 * S2 + S2
> 1210 GOTO 1230
>
> 1220 N1 = ((P9 ^ 2) * S2 / P(I) ^ 2)
> 1230 W = - S(I) * C9
> 1232 V = 1 - ( EXP (W) * C2)
> 1234 N2 = R1 * (N1 + (N1 * V))
> 1240 N2 = INT (N2 * G(I))
Chris, it's been a while since your post, but since you recently posted
the whole program, I took a look at it and figured out what's going on
here.
This fragment of "Lemonade Stand" is used to compute the number
of glasses sold by a particular stand (stand "I").
N1 is used to compute the number of glasses that would be sold
based only on the price per glass, and lines 1190-1220 are formulas
that determine the "price elasticity" of the lemonade market. If the
price of a glass of lemonade at stand I, P(I), is lower, then more
glasses will be sold, up to a limit of 54 glasses at a price of zero.
If the price per glass is less than ten cents (P9 = 10), then the
approximation in line 1200 is used, which causes N1 to go from
54 at P(I) = 0 to 30 at P(I) = 10 cents. For price 10 cents or more,
the formula on line 1220 is used, which implements a demand curve
that drops nonlinearly from 30 at 10 cents/glass to 7.5 at 20 cents,
and asymptotically approaches zero glasses sold for high prices.
Lines 1230-1232 compute the effectiveness of advertising, V, as
a function of the number of signs, S(I). The "advertising boost"
given to the base rate of sales varies from 0 for no signs to 1,
meaning a 100% increase in sales, for a large number of signs.
Because the factor varies as 1-EXP(# of signs/2), the "boost" is
about 63% for two signs, about 86% for four signs, and adding
more signs has a rapidly diminishing effect.
Line 1234 is the key line, since it integrates the effects of the
price/demand curve and the advertising boost, and also multiplies
by the weather factor, R1, which is 1 for normal weather but jumps
to 2 for dry weather. It can drop to 0.1 if street work disrupts your
stand's sales but the stree crews buy lemonade.
Finally, line 1240 incorporates the factor G(I), which is normally
1, but goes to 0 if all stand's sales are "ruined by rain". The
total number of glasses sold for this stand, N2, is also converted
to a whole number.
The formulas used in these calculations for the price/demand
curve and the effectiveness of advertising are somewhat arbitrary
aspects of the Lemonade Stand business model, but they clearly
have a foundation in reality. The formulas could be "tweaked" and
the result would be a somewhat different optimal strategy for
maximizing profits for the players.
Hope this is some help.
-michael
Email: mjmahon@aol.com
Home page: http://members.aol.com/MJMahon/