Homework 4
A. Write a static method that, given two string s and t, returns an array of all positions where t occurs in s. For example, findLocations("Frances ran and ran", "ran") returns [1, 8, 16]. Use a recursive helper method.
Complete this file. The netbrat tester is here.
Draft: Ignore the array, just print the positions
If s or t is empty, return an array of length 0 (i.e. [], not [0] or
null).
B. An AdditionPuzzle has a form such as 2BCD+BCDE=DA01. We want to find a solution, where A, B, C, D are distinct digits, different from any digits in the puzzle. Here, a solution is 2345+3456=5801. In general, a puzzle can have any combination of up to ten digits and numbers.
Write a recursive method for computing a solution to a puzzle, using the Homework4B and Puzzle classes. The netbrat tester is here.
If there are multiple solutions, you can return any one of them.
Draft: Just complete the puzzle. It should pass this tester.
C. Write a method that yields an array list of all subsequences of letters in a word, in the same order in which they appear in the word. The subsequences may skip some letters. For example, "brat" ->
[, a, at, b, ba, bat, br, bra, brat, brt, bt, r, ra, rat, rt, t]
(The first entry is the empty string.) The order in which you generate the
words does not matter. If the word contains duplicate letters (for example,
"barb"), it is ok if some strings are duplicated.
Complete this file. The netbrat tester is here.
Draft: Should work correctly for an input string of length 0, 1, or 2.