[Tutor] comparing seqs by successive intervals
Karl Pflästerer
sigurd at 12move.de
Mon Jan 19 13:37:47 EST 2004
On 19 Jan 2004, Daniel Ehrenberg <- littledanehren at yahoo.com wrote:
> In that algorithm, where does it check to make sure
> that one of the arrays isn't longer than the other?
Nowhere. It wasn't specified.
> They have to be the same length or else the real
> application of seeing if they are transpositions of
> eachother will not work.
He didn't wrote that the sequences had to be of the same length. But if
that's needed it's trivial:
def same_intervp(seq1, seq2):
i = 0
res = []
if len(seq1) == len(seq2):
[Code]
else:
return False
IMO that's more efficient than building two auxiliary lists and
comparing those lists.
If you compute the length anyway the code could be written a bit
different (and simpler):
def same_intervp(seq1, seq2):
res = []
L = len(seq1)
if L == len(seq2):
for i in xrange(L - 1):
d1 = seq1[i+1] - seq1[i]
d2 = seq2[i+1] - seq2[i]
if d1 == d2: res.append(d1%12)
else: return False
return res
else: return False
Karl
--
Please do *not* send copies of replies to me.
I read the list
More information about the Tutor
mailing list