|
MIT OpenCourseWare 6.00 Introduction to Computer Science and ProgrammingClass length: 13 weeks. Start anytime. Creator: duallain Status: Under Construction |
|
Assignment 1Assignment 3: Matching strings: a biological perspective THIS ASSIGNMENT IS NOT DUE FOR THIS LECTURE BUT I AM UNABLE TO REMOVE IT.This assignment is not due until after lecture 5. Please submit this assignment with the next lesson. I apologize for the confusion.Homework Submissions (5 total):ps3a.py from string import *
def countSubStringMatch(target, key):
"""counts the number of times 'key' appears in 'target'"""
counter = 0
next = 0
while find(target, key, next) != -1:
next = find(target, key, next) + 1
counter += 1
return counter
def countSubStringMatchRecursive(target, key):
"""counts the number of times 'key' appears in 'target'"""
counter = 0
if find(target, key) != -1:
counter = 1 + countSubStringMatchRecursive(target[find(target, key)+1:], key)
return counter
Permalink
Comments:ps3b-d.py from string import *
# this is a code file that you can use as a template for submitting your
# solutions
# these are some example strings for use in testing your code
# target strings
target1 = 'atgacatgcacaagtatgcat'
target2 = 'atgaatgcatggatgtaaatgcag'
# key strings
key10 = 'a'
key11 = 'atg'
key12 = 'atgc'
key13 = 'atgca'
### the following procedure you will use in Problem 3
def subStringMatchExact(target,key):
counter = []
next = 0
while find(target, key, next) != -1:
counter += [find(target, key, next)]
next = find(target, key, next) + 1
return tuple(counter)
def constrainedMatchPair(firstMatch, secondMatch, length):
counter = []
for x in firstMatch:
for y in secondMatch:
if x + length + 1 == y:
counter += [x]
return tuple(counter)
def subStringMatchExactlyOneSub(target,key):
exactMatch = subStringMatchExact(target, key)
subMatch = subStringMatchOneSub(key, target)
counter = list(subMatch)
for x in subMatch:
for y in exactMatch:
if x == y:
counter.remove(x)
return tuple(counter)
def subStringMatchOneSub(key,target):
"""search for all locations of key in target, with one substitution"""
allAnswers = ()
for miss in range(0,len(key)):
# miss picks location for missing element
# key1 and key2 are substrings to match
key1 = key[:miss]
key2 = key[miss+1:]
print 'breaking key',key,'into',key1,key2
# match1 and match2 are tuples of locations of start of matches
# for each substring in target
match1 = subStringMatchExact(target,key1)
match2 = subStringMatchExact(target,key2)
# when we get here, we have two tuples of start points
# need to filter pairs to decide which are correct
filtered = constrainedMatchPair(match1,match2,len(key1))
allAnswers = allAnswers + filtered
print 'match1',match1
print 'match2',match2
print 'possible matches for',key1,key2,'start at',filtered
return allAnswers
No comments. Sign up or log in to comment No comments. Sign up or log in to comment No comments. Sign up or log in to comment |
Comments:
6 months ago
this is the correct assignment for this lecture. check the calendar and what has been done so far in this course. the problem set is always one number lower than the lecture number. it's the next one that you fucked up on. and couldn't you remove the assignment and then create a new one?
5 months ago
If you check the calendar, you'll notice it says ps0 is due with lecture2, ps1 is due with lecture 3, and ps2 is due with lecture 4. These dates assume the assignment is being turned in before the lecture.
Given the format of the crunchcourse, I'm assuming everyone watches the lecture before opening the accompanying assignment, so all of the due dates on the MIT calendar need to be pushed up one lesson, which is the way I'm presenting it here.
I can edit assignments but I can't delete them.
Sign up or log in to comment