## Archive for December, 2008

Uncategorized

Here's an interesting interview with Simon Peyton-Jones (SPJ) on Haskell. SPJ wrote the defacto GHC compiler.

Clearly the isolation from side-effects that functions have - due to the immutablity of "variables" lends itself well to parallel programming. Interestingly, Haskell differs from other functional languages like Scheme and ML by virtue of it's lazy evaluation. An expression in Haskell is not evaluated until it is actually used by something.

The more I play with Haskell the more I like the programming paradigm it encompasses (each functional language has it's pros/cons). Functional programming certainly won't usurp imperative, O-O languages but IMHO it will play an increasingly large part in the coming years - especially with Microsoft helping it into the mainstream with the development of their "less-pure" functional language, F#. (SPJ works for Microsoft Research)

Uncategorized

## Smile: Algorithms at Work

Some interesting uses of intelligent algorithms :

http://www.techworld.com.au/article/268095/top_10_wicked_cool_algorithms?img=12305&ssid=1

One that I can add to the list was a feature I recently observed in a friend's Sony camera: smile-detection. You press the fire button and it only takes a picture when the subject is smiling. We tried it out at a Christmas day and it actually works! It seems this technology has been commercially available for a least a year but I've not seen it in person until recently. It's a pleasant surprise when promised technology actually delivers user value

Uncategorized

## Finding the Minimum Without If

Question: Write a function (in C#) to find the minimum of 2 integers. You cannot use any inbuilt functions that provide this functionality and you cannot use any flow-of-control statements like "if" and "while".

Answer: It would be darn easy if it wasn't for those restrictions in the question! So we need to think outside of the box which is the point of this particular problem. You've probably already guessed that it involves a mathematical trick. Here is a function that uses absolute values... try and see if you can figure out why it works.

```        static int Min(int a, int b)
{
return (int)(0.5 * (Math.Abs(a + b) - Math.Abs(a - b)));
}

static void Main()
{
int a = 45;
int b = 67;
Console.WriteLine( Min(a,b) );
}```