pyBoogie


Joined 1 year ago
Homeworks submitted:
Homework comments:
2
1

About Me

I would like to learn more about computer science.

Classes

Programming in C

Class status: Established
Role: Student
. 0% complete

MIT OpenCourseWare 6.00 Introduction to Computer Science and Programming

Class status: Established
Role: Student
. 11% complete

Submitted Assignments

MIT OpenCourseWare 6.00 Introduction to Computer Science and Programming: Lesson 5, HW 1
# Problem Set 3 (Part 1)
# Name: Boogie
# Collaborators: None
# Time: 0:30

from string import *

def countSubStringMatchRecursion(target, key):
    """
    purpose: to count the no. of occurrences of key in target string
    parameters: target - target string, key - search string
    output: count
    """

    indexInTarget = 0
    startIndex    = 0

    while indexInTarget != -1:
        
        indexInTarget = find(target, key)
        if indexInTarget != -1:
            # reset startIndex of target to startIndex + length of the key
            startIndex = indexInTarget + len(key)
            # start new search, with modified target
            return countSubStringMatchRecursion(target[startIndex:],key) + 1

    return 0

def countSubStringMatch(target, key):
    ctr = 0
    indexInTarget = 0
  
    startIndex = 0

    while indexInTarget != -1:
        indexInTarget = find(target, key)
        if indexInTarget != -1:
            ctr = ctr + 1
            startIndex = indexInTarget + len(key)
            target = target[startIndex:]
    
    return ctr


# Problem Set 3 (Part 2)
# Name: Boogie
# Collaborators: None
# Time: 0:30

from string import *

def subStringMatchExact(target, key):

    indexInTarget = 0
    startIndex    = 0

    ans = ()

    while indexInTarget != -1:
        indexInTarget = find(target, key)
        if indexInTarget != -1:
            ans = ans + (startIndex + indexInTarget,)
            startIndex = indexInTarget + len(key)
            target = target[startIndex:]

    return ans




pyBoogie 1 year ago
MIT OpenCourseWare 6.00 Introduction to Computer Science and Programming: Lesson 3, HW 1
# Problem Set 2 (Part 4)                                                                              
# Name: Boogie Devera                                                                                 
# Collaborators: None                                                                                 
# Time: 00:30                                                                                         

bestSoFar = 0

packages = (6, 9, 20)

for n in range(1,200):

    exactQtyFlag = False # does not solve the diophantine equation                                    

    for a in range(0,10):
        for b in range(0,10):
            for c in range(0,10):
                calc =  a * packages[0] + b * packages[1] + c * packages[2]
                if n == calc:
                    exactQtyFlag = True
                    break

    if not exactQtyFlag and bestSoFar < n:
        bestSoFar = n

print "Given packages sizes <6>, <9>, and <20>, the largest number of McNuggets that"
print "cannot be bought in exact quantity is: ", bestSoFar

pyBoogie 1 year ago