Friday, April 20, 2007

Household algorithms

Hi. Today I'd like to talk about algorithms. For the hoi polloi, an algorithm is a set of instructions to solve a problem or accomplish a task of some kind. Because I'm a programmer, I consider myself an expert on algorithms to some degree, because programming is all about the algorithm. Usually it is possible to solve a given problem in eleventy thousand ways, and what separates the good programmer from the bad is the ability to find a sensible solution. Also, what often separates the bad programmer from the good programmer, is the ability to find an astonishingly stupid solution to a simple problem. A solution the good programmer wouldn't even think about, except if they were trying to be creative. Here's an example of a solution to just about everything, in pseudocode, that I really liked (found from this site I generally like):

while(solution isn't correct)

{

solution = Another Randomly Generated Solution;

}

print solution

Sure, eventually it will work, but as a solution to any real problem it is inefficient in astronomical magnitudes. And more specifically, programming is all about the efficient algorithm. Those users are always wanting more speed and efficiency. They don't want to wait. And given that computers have become umpteenillionty times faster in a few decades, it's astonishing that we still have to wait for a few seconds for the browser to start up. I don't understand it either. Why are we constantly battling performance issues, even though the hardware has improved so quickly? Oh, wait a minute, I hear that Windows Vista shows the open program windows in fancy 3D style when you press Alt-Tab, and that is a major selling point. Maybe this is related to the problem somehow.

But to the point. I was going to say something about algorithms used in household keeping. My urge to address the issue was triggered by an algorithm I encountered recently, and that is the one my wife uses to change the bedsheets. And might I say, sorry honey, this is the worst solution ever to changing the bedsheets, which is, by the way, one of my most disliked household tasks. Here's the algorithm (in pseudocode):

remove the old bedsheets // in the morning

while(not bedtime) // this should loop for about 12 hours

{
do nothing (about the situation)
}

ask the husband to put on the new bedsheets

ask the husband, please, to put on the new bedsheets

ask the husband, please (with force), to put on the new bedsheets


while(bedsheets are not changed)

{
try to calm the crying baby
wait while the husband changes the bedsheets
}

if(steam coming out of the husband's ears) {
go to bed
}
else {
complain that the pillowcases do not match the sheets and why did you choose those ugly ones anyway
}

For the non-programmer, here's an explanation of the pseudocode: basically, there are three basic structures in programming (explained by a non-university guy):
1) the program is executed from top to bottom (i.e. 1st line, then 2nd line and so on...)
2) the loop, represented in the examples by while{}: do something repeatedly, until a condition is true
3) the conditional branching, represented in the examples by the if...else structure: if the condition in the brackets is true, do something. If it is false, do some other thing (or do nothing at all).
And the text after the // is a comment, meant only to clarify the purpose of the statement to other programmers. And sometimes, as in this case, supposed to be funny to other programmers.

Well. To be fair, I'm sure I have some silly algorithms too. For instance, the way I wash myself in the sauna has proven to be funny-looking to some (i.e. my wife). And in some social situations, my sense of situation has proven to be inexplicably slow for some reason. Must be some kind of a concurrency issue...

But thanks for reading this again, all three of you. And for the first one to write a non-spam comment, a free banana! Come on, a free banana!

3 comments:

Bugg said...

A free banana! My lucky day. I cannot believe my good fortune. I find myself reading your posts fairly often. It is almost interesting to read "The most boring blog in the world".I am not sure if you noticed that I have previously posted a comment on your post dated 9 January 2007.

Ville said...

Wow, a reader! Hi, Bugg. Here's your banana (hope this works). No, I had not noticed your earlier comment. A reader from Africa, exotic! I must check out your blog...

Bugg said...

Thank you for the banana. It did work. We have quite a lot of bananas here in South Africa, but it is always nice to receive a free one for doing something no one has done before (i.e. posting a comment on this blog).