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?

- 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.
Archived Comments
Is the $10 the budget for all iterations or for each day?
It is your starting budget. That's why I resend it to your UDF so you know how much money you have left.
Will predictedtemp be in Celsius or Fahrenheit?
Good q. It will be in Fahrenheit. I will not tell you the range though. Assume 'normal' American city, July. :)
What about cost of supplies (cups, ice, etc.)?
That's the price per cup. It's everything in together.
Clever... So I assume if our stand makes money, our budget will grow the next day?
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
Nope, no real memory here. I didn't want this to be a -super- long contest, just a few minutes more than 5. ;)
There doesn't appear to be a min/max requirement for pricepercup? Is this correct?
Right. But if you sell Lemonade for 9.99 you probably won't sell many.
Not even on a hot, sunny day? ;)
Hey, do as you see best. ;)
can I use an application variable?
Just realised - what I really want is a variable that can store information about history for the day? I know we can't carry history from day to day. Is it possible to have something in the variables/application/whatever that will allow the intra-day storage?
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
great idea!
can't wait to get started!
No - no app variables. I see how memory would improve the function, but really, I don't want to allow for that level of complexity. Again - think 5 minutes... plus a few more. ;)
Is there any limit on the number of entries?
Ray,
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?
OK,
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
are we allowed to fire off cfhttp requests to hpc clusters?
:)
OK,
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
@Curt - All prices are in cents.
FYI, I'm having fun with the submissions so far.
@Joel - I'd rather you just do one entry please.
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.
Hi Ray - great teaser.
I cannot find your email address, should I just cut and paste my code into your contact form?
My email address is ray, then the at symbol, then camdenfamily, then hit the period on your keyword and type com.