Prelim 1 Review Questions This is *not* a sample prelim: it is too long. 1. Given a string in lower case, replace each vowel with the '*' character. 2. Given a string in lower case, duplicate each vowel in it. Example: 'this example string' should be transformed to 'thiis eexaamplee striing'. 3. Given a vector of numbers, divide it into two vectors, such that the first new vector will contain only the positive numbers, and the second one will contain only the negative numbers. The relative order of the numbers in the new strings must be preserved. Zero values will not be transferred to the new string. Example: [6 0 -3 -5 4 5 1 -9 0 3] should be split into [6 4 5 1 3] and [-3 -5 -9]. 4. Given a numerical vector, replace each of its elements by the average of the element's neighbors. The left neighbor of the first element is the last element, and the right neighbor of the last element is the first element. (Thus you can think of this vector as being circular.) Example: [1 3 2 5 7] should be replaced by [5 1.5 4 4.5 3]. 5. Print all (legal) dates in a year in the following format: [1 1] [1 2] ... [1 31] ... [12 31] Assume that you deal with a non-leap year. 6. Given a DNA string as described in Project 2, compute its complement. 7. Similarly to the exponential function, the cosine function can be approximated by summing a finite number of terms from a well-known sequence: cos(x)=1-x^2/2!+x^4/4!-x^6/6!+x^8/8!-x^10/10!+... Approximate the value of the cosine function of 67 degrees by computing and summing the first 100 terms of this series. Note: The argument of the sequence is in *radians*, not in degrees. You will have to convert degrees to radians. To do that, remember that 180 degrees correspond to pi radians. 8. Generate a vector containing N random numbers in the range -2..2. 9. Consider a 2-dimensional coordinate system and a drunkard standing in its origin (the point with coordinates (0,0)). The drunkard can only take a step parallel to the axes (i.e. he can only make a step "up", "down", "left", or "right"). He makes one *random* step every second, and he can not skip any step. Simulate the drunkard's movements for N seconds, and compute the distance from the origin that he reaches at the end of this interval.