A Competition-Based Version of Ray's Lemonade Selling Simulation
Many of you probably saw Ray Camden's Lemonade Stand Contest Results. I had fun creating a function to enter into that contest, but I lost! Congrats to Geoffrey K. Bentz as the winner.
I was curious, though, to see how the functions would perform in a slightly more realistic simulation. Ray's selling simulation basically treated each function in a vacuum, and the main factor was in making the most cups that you could and selling them for the most money, based on the weather and temperature. That may sound obvious, but if a more competitive environment is created, things aren't quite so straightforward. You need to make an appropriate number of cups, and you need to charge as much as you can for them, but you also need to avoid being priced far above your competition.
Well I went ahead and wrote a version of the simulation that tries to take this into account. It's far from perfect, but basically what it does is:
- It loops over each day like the original does
- It determines the predicted and actual temperature and weather like the original does
- It then feeds the prediction temp and weather into each function and gets back its number of cups and its price
- It sorts the stands in order by cup price, lowest first
- It begins the buying simulation by creating a default pool of customers equal to the number of stands * 100
- It sets a default maximum acceptable price of 50 cents per cup
- It modifies the number of customers and the acceptable max price based on the weather and temperature. In general, nicer weather and hotter temperature increase the customers and the max price, and bad weather and lower temperature decrease customers and their max price.
- It loops over the set of customers and divides them into groups. The group sizes are random, to simulate "waves" of customers coming up to the lemonade stands
- As each group is processed, each person has their max acceptable cup price randomized between +/- 12 cents of the base max price, to provide variability
- The first person in the group finds the stand with the cheapest price that still has cups available and whose price doesn't exceed the customer's randomized maximum price
- When a customer picks their stand, that stand becomes "occupied" and is now not available for other customers in this group. The next customer finds the next best price, etc.
- The variable group sizes are run through until the total number of customers is reached
- At that point, the number of cups each stand sold, along with their profit and budget, are saved
- The day ends and the next day begins
In this way, it's important to sell at a price that makes the stand money, but not so high that its far above what the others are selling for. Even stands selling for cheap prices are out of luck if they don't make enough. Conversely, since the size of the crowds are randomized, as are their price limits, it is easy for a stand to make too many cups and not sell them all.
I ran a 30 day cycle through 30 runs and came up with average rankings for each stand. I also determined the standard deviation for each stand, which is an indicator of consistency. A stand with a large standard deviation was more erratic in its ranking, while a low standard deviation means less variability in its rankings over time.
The level of built-in variation in the simulation causes the results to shift around a bit, but in general Geoffrey Bentz still comes out on top. Usually followed by myself or Mat Evans. Kudos to Stephen Withington, since even though he is not usually the winner, he has a very consistent ranking (low standard deviation) around the 4 or 5 spot. Curt Gratz also does well (I fixed Curt's function to properly deal with cents instead of dollars).
Interestingly, and maybe something of a validation that the more competition-driven simulation actually makes a difference, is that Ray's test "smarterseller" function tended to be in the bottom half of results. Since all that function does is make as many cups as it can, and ignores weather to ramp up the price based on temperature, perhaps that should be expected? This function probably ended many days with a lot of unsold cups.
Anyway, some example results are below. If you are interested, you can see and run the modified simulation code. Thanks again to Ray for running this! Writing the little simulation version was an interesting exercise. Maybe someone else will try an alternate approach or try some of the other ideas that were thrown out (like actually reading historical weather data, or applying a weather pattern algorithm).
Sales Results Across 30 Runs of 30 Days Each
| Stand | Average Ranking ± Std. Deviation |
|---|---|
| BENTZ | 3.87 ± 3.88 |
| MATEVANS | 4.70 ± 5.41 |
| BRIANKOTEK | 5.37 ± 3.23 |
| CURTGRATZ | 6.03 ± 2.88 |
| PADDYROHR | 6.10 ± 4.70 |
| STEPHENWITHINGTON | 6.37 ± 2.69 |
| CFSILENCE | 6.77 ± 3.65 |
| JOHNERIC | 8.00 ± 2.48 |
| MATTOSBUN | 9.63 ± 4.53 |
| JOELSTOBART | 9.80 ± 2.84 |
| SMARTERSELLER | 10.83 ± 5.96 |
| GENTRYD | 10.83 ± 2.37 |
| MATTJONES | 11.03 ± 2.59 |
| BRADWOOD | 11.27 ± 3.07 |
| TUTTLE | 12.40 ± 3.59 |
| CISKE | 13.93 ± 2.26 |
| COYNE | 16.07 ± 1.15 |
Remember:
- Look not only at the average ranking, but at the standard deviation.
- A lower standard deviation means that stand was more consistent in its ranking.
- A higher standard deviation means that stand had a wide variability in its rankings.
- So in the end, consistent performance and a good ranking really make the best stands.




Two questions:
1. When a stand becomes 'occupied', will a customer automatically move to the next open stand, or is there a price difference threshold at which they'll shift? (A customer may stand in line at Stand A if it was 15% +/- (randRange(0, 5)% cheaper than Stand B, which has no line).
2. Do customers have brand loyalty? If I shop with Bentz on Monday, is the decision weighted towards Bentz on Tuesday? Or maybe weighted away, in case Bentz forgot the sugar or was being rude? Maybe there should be a 'customer satisfaction' factor, where one in 4-5 customers isn't happy with their experience and won't use the same person twice, but would otherwise have a weighted decision the next day.
I might try running these over a whole year and see how it pans out, tbh i think people will maintain the same rough position but there might be some surprises.
Thanks!
Also, no brand loyalty, I basically assumed that each day's pool of customers was unique.
Great follow-up! And by the way, do you think 'low standard deviation' would look good on a resume?
Modeling human behavior is a hard beast. This is a great 2nd look at the lemonade stand; interesting read. :-)
I think my entry must be selling much higher than most of the others. Bumping the max price up to $1.25 puts me up at the top from the very bottom when set at $0.50. :) Interesting.
COYNE - $2.07
BENTZ - $0.39
MATEVANS - $0.35
SMARTERSELLER - $0.34
BRIANKOTEK - $0.32
STEPHENWITHINGTON - $0.21
CURTGRATZ - $0.19
TUTTLE - $0.17
PADDYROHR - $0.16
JOHNERIC - $0.15
BRADWOOD - $0.14
MATTJONES - $0.12
CFSILENCE - $0.11
MATTOSBUN - $0.11
JOELSTOBART - $0.11
CISKE - $0.10
GENTRYD - $0.08
Here was my analysis:
http://www.codersrevolution.com/index.cfm/2008/7/1...