Description
1. (5 points)Write a function in Scala that takes in two lists of Ints, and returns a new list of Ints
with the elements of the input lists alternating. So if the input lists were 1, 2, 3, 4 and 7, 8, 9, 10,
11, 12 the output list would be 1, 7, 2, 8, 3, 9, 4, 10, 11, 12. Note that if one list is longer than
the other, the extra elements are added at the end. You may use a helper function with extra
parameters if you like, but this is not necessary.
2. (5 points) Write a function in Scala whose parameters are: two lists of Ints, xs and ys, and a
function f that takes in two Ints and returns an Int; the function should return a new list whose
elements are obtained by applying f to the corresponding elements of xs and ys. Test your
function using anonymous functions corresponding to f(x, y) = x+y and f(x, y) = x*x+y. For
example, if xs was the list 3, 8, 1, 5 and ys was 12, 6, 23, 1, 8, 4 and the f used was f(x, y) = x+y,
our result list would be 15, 14, 24, 6. Note that if one list is longer than the other, the extra
elements are not included in the result list. You may NOT use a helper function with extra
parameters.
3. (10 points) Write a function in Scala that takes in a list xs of Ints, and a function f from Ints to
Booleans, and whose result is a list with only those elements x of xs for which f(x) is true.
Test your function using anonymous functions corresponding to f(x) = x%2==0 and f(x) = x>10.
You may NOT use a helper function with extra parameters.
4. (5 points) Write a curried version of your function from problem 3, which takes in the function
from Ints to Booleans and returns another function that takes in a list of Ints and returns a list
of Ints. You should return an anonymous function, not a named one. You may NOT use a
helper function with extra parameters.
* Submission instructions: You will print out your code for each problem, stapling together
multiple sheets (there will be deductions for unstapled homework!). Turn in the hardcopy at the
beginning of class. You will ALSO submit all of your .scala files as attachments, to
cs169@math.scu.edu (NOT Dr. Linnell’s email!!) The subject line of the email should be “CS169
HW7 YourLastName YourIDNumber “

