[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Finding the common textual denominator



On Sun, 2005-03-06 at 22:10 +0100, Olle Eriksson wrote:

> Is there any application that does this already, or will I have to write 
> something myself?

Maybe there's something out there doing this, but writing
it yourself isn't hard either. A very basic algorithm would
be: if you have n strings s1, s2, ..., sn just take the
first s1 and look wether all other begin with s1. If yes,
you're done. If not, strip the last character off s1 and try
again. At some point, you'll end up either with the empty string,
or a nonempty 'common denominator'. And that's it.

You can write it in awk, perl, C whatever you want. The
algo above is of course primitive, so if you're string
are millions of characters long and you have millions of
them, you'll need to improve it. But 'til then, the above
will do what you want.

Regards, Bruno.





Reply to: