MIT OpenCourseWare 6.00 Introduction to Computer Science and Programming

Class length: 13 weeks. Start anytime.

Creator: duallain

Status: Under Construction

Assignment 1

Assignment 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):

shaggorama (Self-grade: Outstanding)
Submitted 6 months ago
Permalink

Comments:

klaymen
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?

shaggorama
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

klaymen (Self-grade: Outstanding)
Submitted 6 months ago

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:

klaymen
6 months ago

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

Sign up or log in to comment

BTheMad (Self-grade: Could be better)
Submitted 1 month ago

Moved solution to the next lecture

Permalink
Joe (Self-grade: Outstanding)
Submitted 1 month ago

sorry, I didn't see it. move my work to the next lecture.

Permalink
chip (Self-grade: Outstanding)
Submitted 1 month ago
Permalink

Recent Class Activity

hendrix submitted Lesson 12 HW 1
2 days ago
ndwhite13 submitted Lesson 1 HW 1
3 days ago
NawXela submitted Lesson 3 HW 1
5 days ago
chip submitted Lesson 12 HW 1
2 weeks ago
chip submitted Lesson 11 HW 1
2 weeks ago
hendrix submitted Lesson 11 HW 1
3 weeks ago
rs031759 submitted Lesson 2 HW 1
3 weeks ago
rs031759 submitted Lesson 1 HW 1
3 weeks ago

Class Members (198)

ndwhite13
Joined 3 days ago
chrixian
Joined 5 days ago
marcosdecarvalho
Joined 1 week ago
pangor
Joined 2 weeks ago
paroxysm
Joined 2 weeks ago
mkaymer
Joined 2 weeks ago
sundeep
Joined 2 weeks ago
reddog69
Joined 3 weeks ago

All members


License

Attribution Non-Commercial Share Alike