Saint Louis University |
Computer Science 1300
|
Computer Science Department |
Please make sure you adhere to the policies on academic integrity.
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,
If the goal is unachievable, the function should returnĀ 0.
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.