CS 330 Scheme Homework #4
Prerequisite: Scheme Lectures 1-2 Due: May 18, 2020 at 11:59pm
Create Scheme functions for the following:
1. flatten append which has 2 arguments that are both lists. The result should be equivalent to the concatenation of the flattened versions of the first list followed by the flattened version of the second list. Use the built-in functions append and flatten. For example, (flatten append ¡¯(1 2 (3 4 5) (6)) ¡¯((7) (8 (9)))) should re- turn the list ¡¯(1 2 3 4 5 6 7 8 9).
2. combine which has 3 arguments that are all lists. The result should be equivalent to the concatenation of the first list, the reverse of the second list, followed by the third list. Use the built-in functions append and reverse. For example, (combine ¡¯(1 2) ¡¯(3 4 5) ¡¯(6 7))shouldreturnthelist¡¯(1 2 5 4 3 6 7).
3. split which has a single argument that is a list of integers. The result is a list of 2 lists: the first sublist is a list of the positive integers from the input list and the second sublist is the list of the negative integers from the input list. For example, (split ¡¯(1 -2 -3 4 5 6 -7 -8))shouldreturnthelist¡¯((1 4 5 6) (-2 -3 -7 -8)).
4. min max which has a single argument that is a list of integers. The result is a list of 2 integers: the first element is the maximum value that is contained in the input list, and the second element is the minimum value that is contained in the in;ut list. For example, (min max ¡¯(8 -2 5 -6 2 3 -1 0 9 4 1)) should return the list ¡¯(9 -6).
5. perfect squares which has a single argument that is a list of integers. The result is a list of 2 elements: the first element of the result list is a list of the elements from the in- put list that are perfect squares, and the second element of the result list is the number of perfect squares that are contained in the input list. For example, (perfect squares ¡¯(4 3 16 2 8 10 9 7))shouldreturnthelist¡¯((4 16 9) 3).
6. square cube difference which has a single argument that is a list of integers. The result is the difference between the sum of the cubes of the input list and the sum of the squares of the input list. For example, (square cube difference (1 2 3)) should return 22 (since the sum of the squares of the list is 1+4+9 = 14 and the sum of the cubes of the list is 1 + 8 + 27 = 36).
8 points
1
7. standard deviation which has a single argument that is a list of integers. The re- sult is the standard deviation of the list. Note that the standard deviation of a list is the square root of the variance of the list. The variance of the list is the aver- age of the squared difference of each of the numbers from the mean. For example, (standard deviation ¡¯(600 470 170 430 300)) should return 147.32. The mean is 394. The squared difference list is ¡¯(42436 5776 50176 1296 8836), and its aver- age is 21704 which is the variance. So, the standard deviation is 147.32.
8. longest run which has a single argument that is a list of integers. The result is the longest non-decreasing or non-increasing sublist of the input list. A non-decreasing sublist is one in which each element is not less than its predecessor. Likewise, a non- increasing sublist is one in which each element is not greater than its predecessor. For example, (longest run ¡¯(3 5 1 6 8 9 2)) should return ¡¯(1 6 8 9).
2