Course Home | Class Schedule | Moodle CMS | Git Submission | Perusall | Tutoring

Saint Louis University

Computer Science 1300/5001
Introduction to Object-Oriented Programming

Michael Goldwasser

Fall 2019

Computer Science Department

Homework Assignment 12

Please make sure you adhere to the policies on academic integrity.


  1. (10 points)

    Write a function threshold(values, goal) that behaves as follows. The first parameter is a sequence of numbers. The second parameter is a single positive number. The function is to return the smallest possible integer n such that the sum of the first n numbers in the sequence is greater than or equal to goal. For example, threshold([5, 3, 8, 2, 9, 1], 17) should returnĀ 4 because the goal can be achieved by the sum of the first four values (5+3+8+2).

    If the goal is unachievable, the function should returnĀ 0.

  2. (10 points)

    Strings have many convenient behaviors, one of which is that you can test whether a pattern occurs in another string, using the syntax

    pattern in original

    which produces a boolean result.

    We want you to implement this test from basic principles. Provide an implemenation of a function with calling signature

    isSubstring(pattern, original)

    that returns True or False, depending on the given parameters. Furthermore, you must not rely on any of the built-in behaviors of the string class, other than the fact that you can determine their lengths and you can use indexing to retrieve a single character of a string at a given index. That is, you are allowed to use syntaxes such as len(original) or pattern[j], but you must not use any other features of the string class such as find, index, or slicing notation pattern[j:k]. Instead use control structures to look for the pattern yourself, presumably testing every possible placement of where it might occur within the original string, and then testing character-by-character to see if you find a match.


Michael Goldwasser
CSCI 1300/5001, Fall 2019
Last modified: Sunday, 22 December 2019
Course Home | Class Schedule | Moodle CMS | Git Submission | Perusall | Tutoring