Friday Puzzler (a bit early...)
After a bit of a public call out, I realized it was time to start thinking of the Friday Puzzler again. I came up with what I thought was a fun one, but it ended up being something I thought would be a bit more than 5 minutes. So this Puzzler will be for the entire week, and to sweeten the pot a bit, Ben Forta will be sharing a copy of CFWACK (3rd book) with the winner. This isn't a real 'contest' per se, but just a slightly more intense Friday Puzzler. Ready?
The Friday Puzzler will be a Lemonade Stand simulation. The basic idea is simple. Each stand is given a budget of 10 dollars. Each day you will be given a weather prediction (high temp and weather type). Your goal then is to simply determine how many cups of lemonade to make and how much to sell them for. Your code will simply be a UDF. My simulator will run 20 days (the number may change) of iterations. For each day it will call your UDF, get your response, and then determine how well your stand then. Like all weathermen, what is predicted may not actually happen, so you have to take your chances. (Just like real life.) Now for the nitty gritty details.
- Your UDF must 4 arguments.
- The first argument is predictedtemp, a number representing the predicted temperature.
- The second argument is predictedweather. This is a string with 4 types of weather. sunny, clear, rain, or storm. Obviously you will sell more lemonade on sunny days.
- The third argument is cupprice, or the cost (in cents) per cup of lemonade. This will range from 3 to 8 cents.
- The fourth argument is budget. This is how much money (in cents) that you have available.
- Your UDF must return a structure.
- One key is pricepercup, which is how much you will sell your lemonade for (in cents).
- The other key is numberofcups which is the number of cups to make. Note - if you try to make more cups than your budget allows, your UDF will be killed (drawn and quartered). Also note that you cannot make more than 250 cups. You are only human after all.
- Lastly, your UDF must be named ls_X, where X should be your name. This is just to help me organize stuff. So ls_camden would be an example. Yes that's kind of a bad way to name a UDF, but it helps me run my simulator.
Here is an example of a seller that is kind of dumb. All it does is make as many cups as possible. It doesn't check the weather at all.
<cffunction name="ls_aggresiveSeller" output="false" returnType="struct" hint="I sell cheap and make a lot!">
<cfargument name="predictedtemp" type="numeric" required="true" hint="Predicted high temp.">
<cfargument name="predictedweather" type="string" required="true" hint="Predicted weather.">
<cfargument name="cupprice" type="numeric" required="true" hint="Production price.">
<cfargument name="budget" type="numeric" required="true" hint="Their total amount of money.">
<cfset var r = {}>
<cfset r.pricepercup = 20>
<!--- sell as many as possible --->
<cfset r.numberofcups = fix(arguments.budget / arguments.cupprice)>
<!--- production cap is 250 --->
<cfset r.numberofcups = min(250, r.numberofcups)>
<cfreturn r>
</cffunction>
A smarter function would look at arguments.predictedtemp and arguments.predictedweather and adjust the price (and amount).
So any interest? Since this is a competitive contest, please email me your UDF. On Friday I'll blog the results. The winner is the one whose function makes the most money. But I'll also share some of the cooler solutions I see.
Lastly - if anyone wants to throw in another prize or too, be my guest.
Comments
Will we be allowed to make our UDF "remember" what the previous sales were so it can learn how to better market based on trending?
~Brad
The reason for this second message is that I realise that app variables would allow for trending and modelling that you have banned higher up in the discussion.
- Joel
Are there any limits to the pricepercup? Or whatever we think it should be? IE if its 110 degrees and sunny, is $30 ok, assuming of course that I have better then starbucks brand recognition for my lemonade stand. I guess what I am getting at is there any constraints the pricepercup must fall into?
Nevermind Ray, I see after refreshing my page that has been open for 2 days that someone already asked my price constraint question. So please ignore the previous comment.
Thanks
:)
Real question now. Is the pricepercup and the cupprice in dollars or cents? I.E. Return 20 for 20 cents a cup or return .2 for 20 cents a cup?
Thanks
When everything is done, I plan on releasing all the sim code. You can then run it yourself on your multiple functions and see if you picked the best one.
I cannot find your email address, should I just cut and paste my code into your contact form?

