in reply to Re: Substring Distance Problem
in thread Measuring Substrings Problem

In my understanding, ewijaya should automate the substring positioning as well as counting - what I think you have left as an exercise. This part would probably spoil your efficiency claim, because you're solving the problem from quite a convenient starting point :)

This said, I find the final computation quite elegant and istructive - I wouldn't have thought of XORing letters even in 100 years. There's always to learn, luckly, provided I'll be able to remember it when I'll need :)

Flavio (perl -e "print(scalar(reverse('ti.xittelop@oivalf')))")

Don't fool yourself.

Replies are listed 'Best First'.
Re^3: Substring Distance Problem
by tlm (Prior) on Apr 08, 2005 at 14:39 UTC

    This said, I find the final computation quite elegant and istructive - I wouldn't have thought of XORing letters even in 100 years.

    BrowserUk is The XOR Meister.

    I had the same reaction as yours when I first encountered the "infamous xor trick" (in this case to find the first position at which two strings differ, or equivalently, the length of the longest common prefix):

    $a = "foobar"; $b = "foobAr"; ($a ^ $b) =~ /^(\0*)/ and print length $1; __END__ 4
    Way cool, though it works as written only if the characters are 1 byte long.

    There's always to learn, luckly, provided I'll be able to remember it when I'll need :)

    Yep, that's the rub.

    the lowliest monk