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

Is the $10 the budget for all iterations or for each day?
# Posted By Sean | 7/7/08 1:38 PM
It is your starting budget. That's why I resend it to your UDF so you know how much money you have left.
# Posted By Raymond Camden | 7/7/08 2:28 PM
Will predictedtemp be in Celsius or Fahrenheit?
# Posted By Damon Gentry | 7/7/08 2:34 PM
Good q. It will be in Fahrenheit. I will not tell you the range though. Assume 'normal' American city, July. :)
# Posted By Raymond Camden | 7/7/08 2:38 PM
What about cost of supplies (cups, ice, etc.)?
# Posted By Steve Withington | 7/7/08 3:30 PM
That's the price per cup. It's everything in together.
# Posted By Raymond Camden | 7/7/08 3:33 PM
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
# Posted By Brad Wood | 7/7/08 4:08 PM
Nope, no real memory here. I didn't want this to be a -super- long contest, just a few minutes more than 5. ;)
# Posted By Raymond Camden | 7/7/08 4:36 PM
There doesn't appear to be a min/max requirement for pricepercup? Is this correct?
# Posted By Steve Withington | 7/7/08 6:27 PM
Right. But if you sell Lemonade for 9.99 you probably won't sell many.
# Posted By Raymond Camden | 7/7/08 7:58 PM
Not even on a hot, sunny day? ;)
# Posted By Steve Withington | 7/7/08 9:15 PM
Hey, do as you see best. ;)
# Posted By Raymond Camden | 7/7/08 9:27 PM
can I use an application variable?
# Posted By Joel | 7/8/08 2:23 AM
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
# Posted By Joel | 7/8/08 3:49 AM
great idea!

can't wait to get started!
# Posted By Mat Evans | 7/8/08 3:51 AM
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. ;)
# Posted By Raymond Camden | 7/8/08 5:38 AM
Is there any limit on the number of entries?
# Posted By Joel | 7/8/08 7:46 AM
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?
# Posted By Curt Gratz | 7/8/08 3:18 PM
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
# Posted By Curt Gratz | 7/8/08 3:21 PM
are we allowed to fire off cfhttp requests to hpc clusters?

:)
# Posted By Mat Evans | 7/8/08 3:23 PM
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
# Posted By Curt Gratz | 7/8/08 3:28 PM
@Curt - All prices are in cents.
# Posted By Raymond Camden | 7/9/08 6:28 AM
FYI, I'm having fun with the submissions so far.
# Posted By Raymond Camden | 7/9/08 6:29 AM
@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.
# Posted By Raymond Camden | 7/9/08 6:48 AM
Hi Ray - great teaser.

I cannot find your email address, should I just cut and paste my code into your contact form?
# Posted By Paddy Rohr | 7/9/08 12:27 PM
My email address is ray, then the at symbol, then camdenfamily, then hit the period on your keyword and type com.
# Posted By Raymond Camden | 7/9/08 12:38 PM