Monday, May 22, 2006

How to send a mobile phone "business card"?

I always get confused about how to send a person's data saved in my mobile phone address book to another person who is also in my address book. For example, say my friend "seeker" wants to know the contact information about another friend "sought". On my phone which is an antiquated (pre-2003) model of Nokia (I cannot say which one it is since there is nothing on the instrument that tells me what model it is) I can follow the following steps:

- look up information about "sought"
- choose "options" and then choose "send bus. card"
- choose (say) "via text msg."
- look up information about "seeker"
- choose to "send the business card"

I always get confused which order to do my search in (do I lookup "sought" and send his info. to "seeker" or do I look up "seeker" and send him information about "sought"?) and I thought others too may have that confusion hence thought I should record this permanently.

- Rajendra Gokhale

Tuesday, May 02, 2006

Words containing letters in alphabetical order

My daughter Rama asked me this question the other day - which is the longest word that contains all letters in alphabetical order? For a dyed-in-the-wool UNIX hacker like me, the answer was quite straightforward:

grep -i "a*b*c*d*e*f*g*h*i*j*k*l*m*n*o*p*q*r*s*t*u*v*w*x*y*z*" /usr/share/dict/words

Interestingly enough, I had left out the "*" at the end of the regular expression so all the words I found were ones ending in "z". That taught me a new word - "chintz" which interestingly enough originates from Hindi and is a type of cotton fabric. My daughter alerted me to my bug when she pointed out that the word "fix" did not appear in my output. I was able to correct my error and rerun the program. One of the longest words fulfilling the requirements of the problem was "biopsy".

Many of my posts may seem like nice ways to kill time but these skills really come handy in ones day-to-day work - for example, in my role as manager I was able to put my skills to good use in order to figure out the productivity of my (Research) group. But that will be another posting for some other day.

- Rajendra Gokhale

Solving the hexagon problem using Perl




Here is a problem that I see quite often in one of the afternoon papers such as the "MidDay". You are shown a hexagon, all of whose sides are labelled with one English letter (see above). There is another letter at the centre of the hexagon. The challenge is to make as many words of four or more letters from the letters of the hexagon.

In making a word, each letter must be used once only. Each word must contain the central letter. There should be atleast one seven letter word. Plurals, foreign words & proper names are not allowed.

Given such a hexagon (encoded in some format of your choice) and a file consisting of all acceptable words (e.g. /usr/share/dict/words), can you write a program to solve this problem?

See the Perl program below that does this job quite elegantly. A small point - when I used the dictionary on my Redhat Linux (Fedora Core 3), I could not find the seven letter word because it was missing from the dictionary - I had to figure it out manually. The word was "website" and we are talking of the year 2006 A.D. :-)!

Here is the Perl program:

use strict;
my $regex = '^b{0,1}e{0,2}i{0,1}s{0,1}tw{0,1}$';

foreach my $word (<>)
{
chop $word;
my $newword = join "", (sort (split //, $word));
if ($newword =~ /$regex/ && length($word) >= 4){
print "${word}\n";
}
}
__END__
As you can see above, the regular expression from the image shown was hardcoded into the script but anyone who understands this program will be able to trivially modify it so that the regular expression can be constructed on the fly. Also one small optimization that is possible involves precompiling the regular expression.

- Rajendra Gokhale

Sunday, April 16, 2006

Pune passport office information

I needed to get my passport renewed from Pune, India and was not able to find much information about this from the we so I decided to describe my experiences here.

My passport expires in October 2006 but I needed to get it renewed since I needed to get a visa in May 2006 - most countries do not issue a visa unless your passport is valid for at least six months beyond the date of issue of your visa. My impression was that the Government of India did not issue a new passport more than six months before the old passport is due to expire but that is apparently not the case - you can renew your passport upto one year before it is due to expire. Anyway the fact was that I needed to get my passport renewed in less than a month so I needed to go the "Tatkal" route that enables one to get an emergency passport. Note that typical waiting times at Pune are a few months so by Pune (Indian?) standards if you need your passport in less than three months, it constitutes an emergency :-). Here are my experiences getting a Tatkal passport from the Pune Passport Office.



The GoI is one of the biggest enemies of the environment. In order to apply for my passport I had to submit an application along with an elaborate set of supporting documentation, all in triplicate! Some of the documentation I had to submit was ridiculous beyond words - for example, I was required to attach photocopies of eight pages from my old passport and although these pages contained my name and date of birth I still had to provide proof of my date of birth. When I submitted my application I had with me all the following documents, each one in triplicate:
  • letter from bank confirming my address (I did not have a ration card, the ultimate proof in India)
  • letter from "reputed employer" confirming my address
  • bank statement
  • School Leaving Certificate confirming my date of birth
  • my degree certificate confirming that I was qualified for ECNR (Emigration Clearance not Required)
If you plan to submit the application in person, you have to also make sure that all these photocopies are signed by you - if someone else is submitting on your behalf, you must have all these attested by someone qualified to do so plus you have to submit some other statement.

You will need a large number of photographs but that was not a problem for me. I have lived in India long enough that I always carry about 50 photographs on my person at all times (my guess is that twelve should suffice). You will need to glue those photographs at various places and sign on those so that the signature spans both the application form as well as the photographs. Make sure that you have affixed your thumb impression at the right place on all the applications (left thumb for males and right for females).

Here then is the list of items you need:
  • glue stick (one no.)
  • stapler with extra pins
  • stamp pad
  • portable photo-copier
  • two ball point pens (black or blue ink)
  • scissors
  • plastic bag to carry all of the above
  • a friend to assist you
  • a novel/video game etc. to keep you entertained while waiting for your number in various queues
  • and above all, lots of patience ...


Armed with all the required documents and accessories, I reached the passport office on a Wednesday (I think). I will describe all that I learnt there in the form of factoids:

  • there are three steps in the application process.
    1. get a token number from the token number queue.
    2. wait to have your application scrutinized. Since there is a token system in place, you do not have to stand in any queue for this. In this stage, your application will be scrutinized in order to make sure that all your papers are in order. In general, you would have missed out some documents that need to be submitted and you are asked to bring them. For example, I had a valid visa on my current passport and I was asked to get photocopies of that (there are numerous shops providing photocopying service in the vicinity of the office). If your old passport contains valid visas, the passport is cancelled and immediately returned to you - the horror stories about your passport getting stolen etc. seem to be fiction.
    3. When your application has been scrutinized, you have to await your turn at the payment window (again, you do not have to stand in a line - you pay when your number is announced).
  • as mentioned above, I wanted to apply for a Tatkal passport. When I mentioned this to the "scrutiny" lady, she asked me to meet the Passport Officer after I had made my payment. At the payment window they just took the fees for a standard passport from me.
  • sign the token that was given to you at stage 1 of the process before you approach the scrutiny window - this is an undocumented requirement and will earn you brownie points with the lady at the scrutiny window.
  • after paying the fees I went to meet the Passport Officer and told him that I needed my Passport in a hurry - he asked me to come after eight days. Note that by this time it was close to 1 p.m. so there was no line to meet the Passport Officer.
  • I accordingly went to meet him after eight days. This time I had to stand in a long line (make sure you stand in the line to meet the Passport Officer, not the one leading up to the PRO :-) ). After an hour spent in the queue, I got an audience wth him. I had all the documents needed for getting an emergency application. He asked me to write a covering letter. After I did so, he asked me to meet him again after two days.
  • I again met him after two days going through the same process as before. Surprise of surprises - he asked me to come and collect the passport in the afternoon!
I went in the evening and collected my passport. I had got my new Indian passport with a 5 year validity on the tenth day after applying. Not only did I not have to bribe anybody, I didn't even have to pay any special fees! Of course, I had to spend three mornings and one evening, but I guess we are still only in the 21st. century out here :-(.

Lest I sound very matter-of-fact here, let me assure you that the actual experience was extremely annoying for me. I had even exchanged words with the Officer on the first day. However the speed with which I got my passport ultimately was a really pleasant surprise.

I think I will stop now.

- Rajendra Gokhale