Monday, August 11, 2008

Thursday, July 31, 2008

Cuil - Cool - Cold?


The wannabe Google killer Cuil (pronounced cool) failed to impress. Like many others on the net who did the same thing, I tried out ego-searching. What I found was that, it didn't even return 20% of the result what Google gives. Among the ones it returned, interestingly, it somehow associated one of my conference papers to a concentration camp memorial! (See the attached screenshot). Oh, please don't try to be too smart!!

However, as a bonus, when I did a similar search on google to compare, it unearthed a software that I had put on the web around 10 years ago, called Tcl-O-Scope, that I had totally forgotten. I still love you google :)

Oh btw, did I mention that I have advanced to the second round of google code jam 2008!

Cuil has a long way to go.. Unless it warms up and deliver results, it will become permafrost pretty soon!

Sunday, July 13, 2008

Gelatin Balls


Kevin was playing with these which my sister had bought yesterday night. Those tiny dull beads had turned into colorful globules after a few hours in water!

Friday, July 11, 2008

Thursday, July 10, 2008

Interview with Sir Clive Sinclair



When I was studying in 9th/10th standard, ZX Spectrum was my object of desire. I used to buy whatever books on ZX Spectrum I could get hold of. Finally Dad bought me a similar Z-80 based home computer called Color Genie.

The above is a spectacular interview with Sir Clive Sinclair, the man behind ZX Spectrum. Following is an excerpt:

Interviewer: They required you to get to grips with how they worked. You have to engage in primarily things where you played around with programming, and even kids like myself, if you wanted to write a game on the Spectrum that played at a reasonable speed, you have to effectively teach yourself to write Assembler which took a significant degree of technical understanding about how the machine worked. Everything now is very much plug and play. Do you think we miss out in the terms of getting to know how these machines work as a result?

Sir Clive: Very much so, and I regret that, because you know, your generation really understood the computers and today's generation know they are just a tool and they didn't get to grips with them, which I think, I find it very sad.

Spot on Sir! Hats off to you for the incredible inventions! Your work has been immensely inspirational for me and countless others.

Tuesday, June 24, 2008

String Comparison Gotcha in PHP!

Can you expect a mature language that has been around for 13 years, and powering many web sites to do basic string comparison properly? No, not really!!

$x[0] = "10000000000000000000001";
$x[1] = "11011000000000000010101";
$x[2] = "10101010101010101010101";

$toFind = "11011000000000000010001";
$k = array_search($toFind, $x);
echo "match is $k";

$p = ($toFind == $x[1]);
echo "match is $p";

Run the above code and see for yourself! It will match $toFind with $x[1]!! I got hit with this nasty surprise when calling the array_search() function for a programming contest problem. It appears like PHP is truncating these strings, which it thinks are numbers and comparing the first few characters. Can anyone give a logical explanation of what's going on? Am I doing something fundamentally wrong, or is PHP hosed?

Update: Jude pointed that using "strict" flag in array_search() uses "===", and hence gets rid of the problem. But the fundamental question still remains. Why would PHP do an automatic type cast to integer while comparing two strings?

Update 2: The fundamental issue can be traced to this single statement in PHP documentation - "If you compare two numerical strings, they are compared as integers." This was the root of all problems. I don't like that behavior, but hey this is PHP. I have a similar gripe with Tcl as well. Try this:

set x "072"
puts [incr $x]
set y "09"
puts [incr y]

It will print 59, followed by an error 'expected integer but got "09" (looks like invalid octal number)' as Tcl treats any string starting with 0 as octal - a tradition it borrows from C, but unfortunately, it overloads the string type!