If you can read these words, you are doing it correctly.
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.
Check out Example 7.5 (Length) in the course book.
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"!)
Use recursion and call rotate_wheel.
Use map to apply rotate_wheel to every wheel in the list.
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.
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!
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.
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))