Thursday, September 27, 2007

Using Computers to solve Sethu Samudram Controversy

Fig: Nasa Picture of Adam's Bridge
Sethu Samudra is the portion of sea that separates Sri Lanka from India. The sea is very shallow with much of the sea bed formed of limestone rock which joined the two countries in the last ice age.

Sethusamudram became newsworthy in 2005 with the launch by the Indian Government of the Sethusamudram Shipping Canal Project. The project gives India a navigable sea route close to the coast, with a reduction in travel distance of more than 350 nautical miles (650 km) (for larger ships). The project is expected to provide a boost to the economic and industrial development of coastal Tamil Nadu. However it is possible that the project is being done in a hurry without undertaking a proper geological study as shown by this article here. Also there are claims/studies which say that there will be marginal benefits. There aren't going to be any time saving navigating as ships will require pilots to navigate through. Also the bigger ships will not be able to use the route and will continue to go around Sri Lanka. So where does it benefit Tamil Nadu? You can read this article for further englightenment.

The Ram Sethu bridge was called the Adam's Bridge by British Cartographers and this is what used to be in the maps in my school days. According to Muslim legend, Adam crossed there to Adam's Peak, Ceylon, atop which he stood repentant on one foot for 1,000 years. A good article on Adam's Bridge is here. According to Encyclopedia Britannica "Dredging operations, now abandoned, were begun as early as 1838 but never succeeded in maintaining a channel for any vessels except those of light draft. Geologic evidence suggests that Adam's Bridge represents a former land connection between India and Sri Lanka".

The name derives from the episode recounted in the Hindu epic, Ramayana, in which Lord Rama's army builds a bridge to cross over from Rameshwaram to Sri Lanka.

It is amusing to see this fight to prove the existence or non-existence of Ram. One of them speaks like a school kid saying "Which engineering college did Ram study to have built a bridge?". The other is behaving like Satan wanting to cash in on North Indian Hindu sentiments (for sinister vote bank purpose) by creating a controversy on the affidavit by ASI. The centre has now withdrawn it after suspending two ASI officials. And now there is a fatwa issued by some stupid VHP leader Vedanti.

There is a solution for these blokes - A C Program which can search for a keyword in all documents and replace it with a word of their choice. You can replace "Sethu Samudram Project Should Continue" with "Sethu Samudram Project Shouldn't continue" or vice versa. Whoever can make this program faster or run it on faster computers will win. Can anyone write a faster version?

The program was written in the year 1998 in a beautiful language called C. After reading you might agree with me that Programming in C is better than politics. Become a C Programmer and you will always have a blissful life.

Also these people want to have a debate on Ramayana as given here. If they want to argue they can take help from my other C Program which Prepares Arguments here.
/*
* $Log: replacestr.c,v $
* Revision 1.4 2001-12-02 20:22:15+05:30 Cprogrammer
* added function getversion_replacestr_c()
*
* Revision 1.3 2001-12-01 23:09:03+05:30 Cprogrammer
* Initial revision
*
*/
#include "stdlib.h"
#include "string.h"

#ifndef lint
static char sccsid[] = "@(#)replacestr.c 1.2 Cprogrammer 05/26/98 13:51:05";
#endif

/*
* function to replace all occurence of string ch with rch in str. NOTE:
* pointer returned by replace should be freed when not needed
*/
char *
replacestr(str, ch, rch)
char *str, *ch, *rch;
{
int len1, len2, diff, slen, resize;
char *ptr1, *ptr2, *tmptr, *svptr;

if(!strstr(str, ch))
return(str);
/* copy all necessary strings */
for (ptr1 = str, slen = 0; *ptr1; ptr1++)
slen++;
for (ptr1 = ch, len1 = 0; *ptr1; ptr1++)
len1++;
for (ptr1 = rch, len2 = 0; *ptr1; ptr1++)
len2++;
/* allocate memory to hold the replaced string */
if (!(tmptr = (char *) malloc(sizeof(char) * (strlen(str) + 1))))
return ((char *) 0);
diff = len2 - len1;
len2 = 0;
resize = 1;
for (ptr1 = str, ptr2 = tmptr; *ptr1; ptr1++)
{
/* realloc as no space left in tmptr */
if (len2 > slen - diff)
{
resize++;
if (!(svptr = (char *) realloc((void *) tmptr, sizeof(char) * resize * (strlen(str) + 1))))
{
(void) free((void *) tmptr);
return ((char *) 0);
}
tmptr = svptr;
ptr2 = tmptr + len2;
}
if (*ptr1 == *ch)
{
/*
* we found the string to be replaced. This can be made
* faster if replacement is done along with comparision
*/
if (!memcmp(ptr1, ch, len1))
{
if(*rch) /* if replacement char is not NULL */
{
svptr = ptr1;
for (ptr1 = rch; *ptr1; ptr1++)
*ptr2++ = *ptr1;
len2 += len1 + diff;
ptr1 = svptr;
}
/* go past the replaced string */
ptr1 += len1 - 1;
continue;
} else
*ptr2++ = *ptr1;
} else
*ptr2++ = *ptr1;
len2++;
}
*ptr2 = 0;
return (tmptr);
}

void
getversion_replacestr_c()
{
write(1, sccsid, 50);
return;
}