I have an answer for problem set 2, #4 at http://dpaste.com/579904/. But, I feel that there should be a more efficient solution. The problem is in my constrainedMatchPair routine. There should be a way to include only instances when the position of the first key is less than the position of the second key. Also, would someone please share the syntax for creating a list of lists? When I had syntax like this: matchList = matchList + ((key1Start, key2Start)) I would get answers like (5, 7, 15, 17) when what I wanted was ((5, 7), (15, 17)) Thanks!
lists are surrounded by square brackets [] tuples are surrounded by parenthesis () use the append method: list.append([1, 2]) i had two for loops and one test - for the test i used the equation given in the problem description. didn't worry about optimization because it was fast enough.
Thanks much for your help. Mine seemed pretty fast, too. But, I knew it wasted cycles making comparisons when the first substring fell after the second. In a revised version I just made at ( http://dpaste.com/580800/), the outer loop steps forward through a list of starting points for the first substring. But, the inner loop steps backward through the positions of the second substring and stops when is sees the second falling before the first. This cut the number of iterations by 38%.
that dpaste is expired so i couldn't see it. i haven't really tested this ... may have gotten it down to just one loop through firstMatch using the equation from the pset and the 'in' operator http://dpaste.com/581290/
Join our real-time social learning platform and learn together with your friends!