The Science of Banana Numeration

Yesterday, as I was regarding a bunch of bananas in the kitchen, I mentally dashed off this code snippet:

#typedef enum {

Banana_Green = 0,

Banana_Yellow,

Banana_Spotted,

Banana_Brown

} BananaRipeness;

#typedef enum {

Take_Banana = 0,

Hold_Out_For_Banana_Bread

} BananaAction;

– (BananaAction) takeBanana:(BananaBunch *)bunch

{

if ( (0 == [bunch count]%3) && [bunch ripeness] > Banana_Yellow ) {

return Hold_Out_For_Banana_Bread;

}

else {

return Take_Banana;

}

}

People who live in houses where banana bread is made will, of course, understand at a glance that when the bananas are getting on in ripeness and there is a multiple of three bananas remaining, one does not take a banana, but rather one holds out for banana bread, lest they face the ire of their fellow residents. Some debate is possible whether the ripeness threshold should be past yellow, as in my code here, or whether one should start holding out earlier, even though the bananas still have a few days left.

It is very good to be in a house where banana count is important.

Code notes: this is written in (more or less) Objective-C, and assumes there is already defined a collection called BananaBunch. I generally avoid multiple exit points in a function, but this one is simple enough that I decided it was OK. I haven’t bothered checking the code for errors, it’s just not that sort of exercise.

Give ’em the Razors, Sell ’em the Blades…

I’m hanging with That Girl, and the other day we were out on the town together, shopping for a variety of techno-things for our office. One of those items was a printer. We spent time at OfficeMax looking at a variety of options, and finally settled on a competent-looking Epson for seventy bucks. I was struck by couple of observations as we lifted the black beauty from it’s packaging and set to work hooking it up:

  1. The cable to connect the printer to the computer is not included. This is mentioned in small print. Oddly, It is not possible to tell from the outside of the box what cable is required. You must get home, unwrap the printer to find no cable, then make a separate trip. Thanks, Epson. (Thanks also to the almost overly-helpful people at OfficeMax, who probably should have known about this.)
  2. The cost of a printer, including a full complement of ink cartridges: $70. The cost of a full complement of ink cartridges: $80. It is cheaper to buy a second printer and throw it away than to buy a backup set of cartridges. Wow. Just… wow.