Friday, October 03, 2008


One of my favorite ploy to those who newly joined my previous company was to give them a command line application and ask them to find out how it worked. This magic command line tool happens to guess your gender if you give your name.

char lastc = argv[1][strlen(argv[1])-1];

printf("%s is a %s\n", argv[1], (lastc == 'a' || lastc == 'i') ? "She" : "He");

Basically, it checks to see if your name ends with an 'a' or an 'i' and if it does, assumes that the person is a lady. Chances are, 95% of most Indian names fall into this category and this simple app seems to do magic.

Most were able to (after a few tries) guess the grand algorithm, but a few poor souls could not, which eventually leads to step number 2.

Step #2 is, as they were unable to decipher the algorithm, I said that I will provide with two separate command line apps called whoisshe and whoishe. I also mentioned that as I had not done the validation part properly, to please provide only men's name to whoishe and a ladies name to whoisshe. If they provide the wrong name, the results could be wrong as well. The code for whoisshe is as follows:

printf("%s is a she\n", argv[1]);

And appropriately modified for whoishe.

The aim is to see how long our new joinee continues to test these tools... Wicked!

No comments: