You are on your honor to make a good-faith effort to solve problems on your own, or with your partners, before using these hints. This typically means at least 10 minutes of brainstorming, attacking the problem with pencil and paper, drawing small diagrams, and so on. The hints are provided with the intention of reducing frustration when course staff support is not available. Remember that the main purpose of this problem set is to help you prepare for Exam 1, so it will defeat that purpose if you use the hints in place of thinking about the problems yourself.
The hints are written in white text on a white background. On most browsers you make the hint visible by moving your mouse over it. If that doesn't work, click your mouse on the screen and drag it over the box: the text will become visible. Try it out on the apparently-empty box below:

If you can read these words, you are doing it correctly.

Question 3

string_to_baudot Hint 1:

Remember that you can use [0] and [1:] on a string just like you can on a list. Use map or write a recursive procedure that applies char_to_baudot to each element of the string.




baudot_to_string Hint 2:

Use map, then use char_list_to_string to convert your list of characters to a string.




Question 4

Running Time Hint 1:

Check out Example 7.5 (Length) in the course book.




Question 5

rotate_wheel Hint:

You want to take the "rest" of the list and append it to the "first" element of the list. (Watch out for the "most common list mistake"!)




Question 6

rotate_wheel_by Hint:

Use recursion and call rotate_wheel.




Question 7

rotate_wheel_list Hint:

Use map to apply rotate_wheel to every wheel in the list.




Question 9

Running Time Hint 1:

The running time of rotate_wheel_list_by depends on both inputs — the wheels passed in and the number of rotates, n. To avoid confusion, use w to represent the number of wheels, p to represent the number of positions in each wheel (fixed as 5 in the problem set, but the procedure we defined would work for any length), and r as the number of rotates to do (the value passed in as n). Express your answer in terms of those three variables.
How much work are we doing per wheel? How many wheels are there?




Running Time Hint 2:

From Example 7.4, list_append has running time in Θ(l) where l is the number of elements in the first list passed to list_append.




Running Time Hint 3:

We are doing Θ(p * r) work for each wheel, and there are w wheels.




Question 10

wheel_encrypt Hint:

The map procedure we defined only works on one list at a time, but this problem requires processing two lists at once. Ambitious students will define a twolist_map procedure that takes a procedure and two lists as its inputs. The input procedure should take two inputs. The output of twolist_map is the list that result from applying the input procedure to each of the corresponding elements from the two input lists. For example, twolist_map(lambda a,b : a+b, [1, 7, 3], [9, 5, 2]) should evaluate to [10, 12, 5].

wheel_encrypt Hint 2:

The built-in map procedure already works on any number of input lists! For example, map(lambda a,b: a+b, [1, 7, 3], [9, 5, 2]) evaluates to [10, 12, 5]

wheel_encrypt Hint 3:

Use map to apply xor to two lists: the Baudot letter (which is just a list of bits) and the list consisting of the first part of each wheel. How can you get the first part of each wheel? map again!




Question 12

do_lorenz Hint 1:

This is a recursive procedure in which the base case is len(code) == 0, the results are combined and the recursive call is to do_lorenz with each of the four arguments modified as per the text.




do_lorenz Hint 2:

This works as the heart of the recursive call:
 if len(code) == 0:
  return []
 if Mwheel[0] == 1:
  return ['?']
 else:
  return ['?']
... but you'll still need two calls to wheel_encrypt to make things work.







Question 14

brute_force_lorenz Hint 1:

To call something on all of the numbers between 0 and 4, we might do:
map(lambda i: something(i), range(5))







brute_force_lorenz Hint 2:

To consider all pairs of numbers between 0 and 4, we might do:
 map(
  lambda i :   map(lambda j :
   something(i, j),
   range(5)),
  range(5))