wolfei


Joined 5 months ago
Homeworks submitted:
Homework comments:
4
2

About Me

No description provided.

Classes

MIT OpenCourseWare 6.00 Introduction to Computer Science and Programming

Class status: Established
Role: Student
. 23% complete

Submitted Assignments

MIT OpenCourseWare 6.00 Introduction to Computer Science and Programming: Lesson 5, HW 1

it took me a while to finish this assignment, i had trouble understanding what they wanted me to do in the last two problems.....gladly i think i have done it properly :)

from string import *

#  target strings

target1 = 'atgacatgcacaagtatgcat'
target2 = 'atgaatgcatggatgtaaatgcag'

# key strings

key10 = 'a'
key11 = 'atg'
key12 = 'atgc'
key13 = 'atgca'

#####################################
##### Problem Set 1             #####  
##### Name: Wolfei              #####  
##### Collaborators: Internet   ##### 
##### Time: pending             #####

def countSubStringMatch(target, key):
    instance = 0
    w = 0 
    while find(target, key, w) != -1:
        instance += 1
        w = find(target, key, w) + 1
    return instance
     
def countSubStringMatchRecursive(target, key):
    instance = 0 
    for lmao in range(0,len(target)):
        if target[lmao:len(key)+lmao] == key:
            instance += 1
    return instance


#####################################
##### Problem Set 2             #####  
##### Name: Wolfei              #####  
##### Collaborators: Internet   ##### 
##### Time: pending             #####
            

def subStringMatchExact(target, key):
    instance = 0
    w = 0
    group = ()
    while find(target, key, w) != -1:
        group = group + (find(target,key,w),)
        instance += 1
        w = find(target, key, w) + 1
    return group
    
    
def subStringMatchExact2(target, key):
    group = ()
    instance = 0 
    for lmao in range(0,len(target)):
        if target[lmao:len(key)+lmao] == key:
            group = group + (lmao,)
            instance += 1
    return group




#####################################
##### Problem Set 3             #####  
##### Name: Wolfei              #####  
##### Collaborators: Internet   ##### 
##### Time: pending             #####


### Function given to help complete problem 3


def subStringMatchOneSub(target,key):
    """search for all locations of key in target, with one substitution"""
    allAnswers = ()
    if len(key) != 1:
        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)
    ##        print match1, match2
            # 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
    else: return " your key has only 1 character, therefore it could substitude all characters in the string"

def constrainedMatchPair(firstMatch,secondMatch,length):
    group = ()
    for lmao in secondMatch:
        for lol in firstMatch:
            if lol+length+1 == lmao:
                group = group + (lol,)
    return group 
    


#####################################
##### Problem Set 4             #####  
##### Name: Wolfei              #####  
##### Collaborators: Internet   ##### 
##### Time: pending             #####


def subStringMatchExactlyOneSub(target,key):
    x = subStringMatchOneSub(target,key) #long one
    y = subStringMatchExact(target,key)  #short one
    if len(key) != 1:
##        print x,y
##        print subStringMatchExactlyOneSub(x,y)
        x, y = givenumbers(x,y)
        if len(x) == 0:
            print "there isn't an incorrect character in the string "
        else:
            print " This is your number"
            return x
    else:return " your key needs at least two characters in it"
        
    
def givenumbers(x,y):
##    tuple(x)
##    tuple(y)
    
    for n in range(len(y)):
        dummy03(x,y)
        x, y = dummy03(x,y)
##        print dummy03(x,y)
##        print x, y
    return x , y


    
def dummy03(x,y):
##    a = subStringMatchOneSub(key,target) long one
##    b = subStringMatchExact(target,key)  short one
##    group = ()
##    x = 5,15,5,15,0,15,5
##    y = 5,15
    group = ()

##    while len(y) != 0:
    for XXX in x:
        if y[0] != XXX:
            group += (XXX,)
##    print group, x
    x = group
    y = y[1:]
    return x, y

wolfei 1 month ago
MIT OpenCourseWare 6.00 Introduction to Computer Science and Programming: Lesson 3, HW 1

Programming rawr

##### Assignment 2              #####
#####################################
##### Problem Set 1             #####  
##### Name: Wolfei              #####  
##### Collaborators: Internet   ##### 
##### Time: pending             #####


##    6       9       20
##    12      18      20      50
##    6       45      0       51
##    12      0       40      52
##    24      9       20      53
##    9       0       0       54
##    6       9       40      55
##
##    We can easily derive the next amounts (56....65) like this
##    (12 + 18 + 20) + 6  =  56
##    (6 + 45 + 0 ) + 6   =  57
##    (12 + 0 + 40) + 6   =  58
##    (24 + 9 + 20) + 6   =  59
##    (9 + 0 + 0) +  6    =  60
##    (6 + 9 + 40) + 6    =  61
##
##    Now we use the newly created and add 6 to them as we did with
##    original ones
##
##    [(12 + 18 + 20) + 6] + 6 =  62
##    [(6 + 45 + 0 ) + 6] + 6 =   63
##    [(12 + 0 + 40) + 6] + 6 =   64
##    [(24 + 9 + 20) + 6] + 6 =   65
    

##### Problem Set 2             #####  
##### Name: Wolfei              #####  
##### Collaborators: Internet   ##### 
##### Time: pending             #####

##The theorem is true because once we have found how to create x, x+1, ....x+5
##we can easily find the next combinations of macnuggets that will lead us to
##higher quantities by adding 6 to x, x+1, ...x+5



##### Problem Set 3             #####  
##### Name: Wolfei              #####  
##### Collaborators: Internet   ##### 
##### Time: 3 weeks             #####


def Problem3():
    x = []
    n = 1
    while n < 200+1:
        if lolcakeA(n) or lolcakeB(n) or lolcakeC(n) == 1:
##            print "saving n", n
            n += 1
        else:
##            print "n isnt good", n
            x += [n]
            n += 1

    print "Largest number of McNuggets that cannot be bought in exact quantity is :"
    raw_input()
    print x[-1]


def lolcakeA(x):
    a = 0
    b = 0
    c = 0
     
    for a in range (0,8+1):
        if 6*a+9*b+20*c == x:
            return 1
        else:
            for b in range (0,5+1):
                if 6*a+9*b+20*c == x:
                    return 1
                else:    
                    for c in range (0,3+1):
                        if 6*a+9*b+20*c == x:
                            return 1
    return 0
                            
    
def lolcakeB(x):
    a = 0
    b = 0
    c = 0
   
    for b in range (0,40+1):
        if 6*a+9*b+20*c == x:
            return 1
        else:
            for c in range (0,40+1):
                if 6*a+9*b+20*c == x:
                    return 1
                else:    
                    for a in range (0,40+1):
                        if 6*a+9*b+20*c == x:
                            return 1
    return 0
    
def lolcakeC(x):
    a = 0
    b = 0
    c = 0

    for c in range (0,40+1):
        if 6*a+9*b+20*c == x:
            return 1
        else:
            for a in range (0,40+1):
                if 6*a+9*b+20*c == x:
                    return 1
                else:    
                    for b in range (0,40+1):
                        if 6*a+9*b+20*c == x:
                            return 1
    return 0


##### Problem Set 4             #####  
##### Name: Wolfei              #####  
##### Collaborators: Internet   ##### 
##### Time: pending             #####

def Problem4():
    
    
    lista = []
    n = 1
    x = input(" tell me the lowest number:  ")
    y = input(" tell me the number in the middle:  ")
    z = input(" tell me the highest number:  ")
    packages = (x, y, z)
    while n < 200+1:
        if lolcakeA2(n,x,y,z) or lolcakeB2(n,x,y,z) or lolcakeC2(n,x,y,z) == 1:
            n += 1
        else:
            lista += [n]
            n += 1

    print ""
    print "Given package sizes",  x , y, "and",  z, 
    print "the largest number of McNuggets that cannot be bought in exact quantity is:", lista[-1] 
      
        

def lolcakeA2(n, x, y, z):
    """ n = number you want to check,  [xyz] are number of packages of McNuggets"""
    x = 0
    y = 0
    z = 0
     
    for x in range (0,40+1):
        if 6*x+9*y+20*z == n:
            return 1
        else:
            for y in range (0,40+1):
                if 6*x+9*y+20*z == n:
                    return 1
                else:    
                    for z in range (0,40+1):
                        if 6*x+9*y+20*z == n:
                            return 1
    return 0

def lolcakeB2(n, x, y, z):
    """ n = number you want to check,  [xyz] are number of packages of McNuggets"""
    x = 0
    y = 0
    z = 0
     
    for y in range (0,40+1):
        if 6*x+9*y+20*z == n:
            return 1
        else:
            for z in range (0,40+1):
                if 6*x+9*y+20*z == n:
                    return 1
                else:    
                    for x in range (0,40+1):
                        if 6*x+9*y+20*z == n:
                            return 1
    return 0

def lolcakeC2(n, x, y, z):
    """ n = number you want to check,  [xyz] are number of packages of McNuggets"""
    x = 0
    y = 0
    z = 0
     
    for z in range (0,40+1):
        if 6*x+9*y+20*z == n:
            return 1
        else:
            for x in range (0,40+1):
                if 6*x+9*y+20*z == n:
                    return 1
                else:    
                    for y in range (0,40+1):
                        if 6*x+9*y+20*z == n:
                            return 1
    return 0

wolfei 2 months ago
MIT OpenCourseWare 6.00 Introduction to Computer Science and Programming: Lesson 1, HW 1

Problem set 0

# Problem Set 0
# Name: Fer
# Collaborators: 
# Time: 00:30

first = raw_input('what is your last name? ')
    last = raw_input('what is your first name? ')
    print first, last

wolfei 5 months ago
MIT OpenCourseWare 6.00 Introduction to Computer Science and Programming: Lesson 2, HW 1

problem 1- done problem 2- done too :D

##### Assignment 1              #####
#####################################
##### Problem Set 1             #####  
##### Name: Wolfei              #####  
##### Collaborators: Internet   ##### 
##### Time: 1 week              #####
def PrimeSolver3():
    a = 1
    b = 1
    c = a-1
    d = 1
    counter = 2
    i = 1
    divisors = 0
    
    while counter <= 1000:#number of prime to stop 
        if ((a/2)*2) != a:#odd numbers go through
            if divisorFinder(a) == 1:#numbers with 1 divisor go through
                print a, counter
                a += 1
                counter += 1
            else:a+=1
        else: a += 1
    print 'THE 1000TH PRIME NUMBER IS', (a-1)


def divisorFinder(x):
    """ Finds the Divisors of any number"""
    a = 1
    numberofdivisors = 0
    while(a<x):
        if x%a == 0:#numbers that divide perfectly pass
            a = a + 1
            numberofdivisors += 1
        else: a = a + 1#otherwise sent back to loop with an added 1
    return numberofdivisors

#####################################
##### Problem Set 2             #####  
##### Name: Wolfei              #####  
##### Collaborators: Internet   ##### 
##### Time: 2days               #####
from math import*

def SumsandRatio(n):
    """ SumLog(primes) and ratio between <<< and n"""
    a = 1
    b = 1
    c = a-1
    d = 1
    counter = 0
    i = 1
    divisors = 0
    sumlogs = log(2)
    
    while counter <= n:#number of prime to stop 
        if ((a/2)*2) != a:#odd numbers go through
            if divisorFinder(a) == 1:#numbers with 1 divisor go through
                logs = log(a)
                sumlogs += logs
                a += 1
                counter += 1
            else:a+=1
        else: a += 1
        counter += 1
    print 'The sum of logs  = ', sumlogs
    print 'Number n = ', n
    print 'Ratio between sumoflogs and n is :', sumlogs/n
    

wolfei 5 months ago