[Tutor] comparing seqs by successive intervals

Daniel Ehrenberg littledanehren at yahoo.com
Mon Jan 19 11:45:10 EST 2004


--- Karl Pflästerer <sigurd at 12move.de> wrote:
> On 19 Jan 2004, kevin parks <- kp8 at mac.com wrote:
> 
> > Actually I am doing something similar to this in
> some other code. I
> > have something that removes duplicates and sorts
> the items beforehand,
> > then normalizes as above. And of course
> normalizing will show that
> > there are indeed transpositions (i have code that
> does this too) but i
> > was intrigued and puzzled by this idea of
> measuring the intervals
> > between successive list items and wanted to see
> how that could be done
> > and then compared to another list, because i
> eventually find a way to
> > see how far away the transposed items are....
> eventually.
> 
> Here is a different approach; it traverses the
> sequences in parallel;
> you will first see a difference if you have long
> sequences (then mine
> approach might be a bit faster).
> 
> def same_intervp(seq1, seq2):
>     i = 0
>     res = []
>     while True:
>         try:
>             d1 = seq1[i+1] - seq1[i]
>             d2 = seq2[i+1] - seq2[i]
>         except IndexError:
>             return res
>         else:
>             if d1 == d2:
>                 res.append(d1%12)
>                 i += 1
>             else:
>                 return False
> 
> 
> 
>    Karl
> -- 
> Please do *not* send copies of replies to me.
> I read the list

In that algorithm, where does it check to make sure
that one of the arrays isn't longer than the other?
They have to be the same length or else the real
application of seeing if they are transpositions of
eachother will not work.

Daniel Ehrenberg

__________________________________
Do you Yahoo!?
Yahoo! Hotjobs: Enter the "Signing Bonus" Sweepstakes
http://hotjobs.sweepstakes.yahoo.com/signingbonus



More information about the Tutor mailing list