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. </ul> 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.
Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate for Extend by Auth0. He focuses on serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support.

Lafayette, LA