Friday Puzzler (a bit early...)

This post is more than 2 years old.

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.">
&lt;cfset var r = {}&gt;

&lt;cfset r.pricepercup = 20&gt;
&lt;!--- sell as many as possible ---&gt;
&lt;cfset r.numberofcups = fix(arguments.budget / arguments.cupprice)&gt;

&lt;!--- production cap is 250 ---&gt;
&lt;cfset r.numberofcups = min(250, r.numberofcups)&gt;

&lt;cfreturn r&gt;


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.

Raymond Camden's Picture

About Raymond Camden

Raymond is a senior developer evangelist for Adobe. He focuses on document services, JavaScript, and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA

Archived Comments

Comment 1 by Sean posted on 7/7/2008 at 10:38 PM

Is the $10 the budget for all iterations or for each day?

Comment 2 by Raymond Camden posted on 7/7/2008 at 11:28 PM

It is your starting budget. That's why I resend it to your UDF so you know how much money you have left.

Comment 3 by Damon Gentry posted on 7/7/2008 at 11:34 PM

Will predictedtemp be in Celsius or Fahrenheit?

Comment 4 by Raymond Camden posted on 7/7/2008 at 11:38 PM

Good q. It will be in Fahrenheit. I will not tell you the range though. Assume 'normal' American city, July. :)

Comment 5 by Steve Withington posted on 7/8/2008 at 12:30 AM

What about cost of supplies (cups, ice, etc.)?

Comment 6 by Raymond Camden posted on 7/8/2008 at 12:33 AM

That's the price per cup. It's everything in together.

Comment 7 by Brad Wood posted on 7/8/2008 at 1:08 AM

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?


Comment 8 by Raymond Camden posted on 7/8/2008 at 1:36 AM

Nope, no real memory here. I didn't want this to be a -super- long contest, just a few minutes more than 5. ;)

Comment 9 by Steve Withington posted on 7/8/2008 at 3:27 AM

There doesn't appear to be a min/max requirement for pricepercup? Is this correct?

Comment 10 by Raymond Camden posted on 7/8/2008 at 4:58 AM

Right. But if you sell Lemonade for 9.99 you probably won't sell many.

Comment 11 by Steve Withington posted on 7/8/2008 at 6:15 AM

Not even on a hot, sunny day? ;)

Comment 12 by Raymond Camden posted on 7/8/2008 at 6:27 AM

Hey, do as you see best. ;)

Comment 13 by Joel posted on 7/8/2008 at 11:23 AM

can I use an application variable?

Comment 14 by Joel posted on 7/8/2008 at 12:49 PM

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

Comment 15 by Mat Evans posted on 7/8/2008 at 12:51 PM

great idea!

can't wait to get started!

Comment 16 by Raymond Camden posted on 7/8/2008 at 2:38 PM

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. ;)

Comment 17 by Joel posted on 7/8/2008 at 4:46 PM

Is there any limit on the number of entries?

Comment 18 by Curt Gratz posted on 7/9/2008 at 12:18 AM


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?

Comment 19 by Curt Gratz posted on 7/9/2008 at 12:21 AM


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.


Comment 20 by Mat Evans posted on 7/9/2008 at 12:23 AM

are we allowed to fire off cfhttp requests to hpc clusters?


Comment 21 by Curt Gratz posted on 7/9/2008 at 12:28 AM


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?


Comment 22 by Raymond Camden posted on 7/9/2008 at 3:28 PM

@Curt - All prices are in cents.

Comment 23 by Raymond Camden posted on 7/9/2008 at 3:29 PM

FYI, I'm having fun with the submissions so far.

Comment 24 by Raymond Camden posted on 7/9/2008 at 3:48 PM

@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.

Comment 25 by Paddy Rohr posted on 7/9/2008 at 9:27 PM

Hi Ray - great teaser.

I cannot find your email address, should I just cut and paste my code into your contact form?

Comment 26 by Raymond Camden posted on 7/9/2008 at 9:38 PM

My email address is ray, then the at symbol, then camdenfamily, then hit the period on your keyword and type com.