In this coding challenge we are providing you with starter code, CC4-template.scm. You should download this file and upload the given code to a new .scm file named lists-and-style.scm.
At the top of your file, make sure to include your name, and any acknowledgements according to our collaboration policy. Now is a great time to review those collaboration policies.
You may recall that we are starting to think about a standard “data science” approach to data in which you clean data, filter data, transform data, and then compute one or more summaries. Let’s start thinking more about how we might write some of these procedures.
For each of the following, you should include complete documentation for every procedure, as described/following the style of our course.
Write a procedure, (restrict-to-range lst lb ub) that returns the elements of lst that are between lb and ub, inclusive. You may choose to rearrange the elements. For example,
> (restrict-to-range (list 5 1 2 8 4 3 19 -5 2 4) 1 4)
'(1 2 2 3 4 4)
Write a procedure, (outside-of-range lst lb ub) that does the opposite: Extracts the elements of lst that are either less than lb or greater than ub.
> (outside-of-range (list 5 1 2 8 4 3 19 -5 2 4) 1 4)
'(-5 5 8 19)
Write a procedure, (scale-by-max lst), that divides every element of the list by the largest value in the list.
> (scale-by-max (list 5 1 2 8 4 3 19 -5 2 4))
(list 0.2631578947368421 0.05263157894736842 0.10526315789473684 0.42105263157894735 0.21052631578947367 0.15789473684210525 1 -0.2631578947368421 0.10526315789473684 0.21052631578947367)
Write a procedure, (scale-by-average lst), that divides every element of the list by the average value in the list.
> (scale-by-average (list 5 1 2 8 4 3 19 -5 2 4))
(list 1.1627906976744187 0.23255813953488372 0.46511627906976744 1.8604651162790697 0.9302325581395349 0.6976744186046512 4.4186046511627906 -1.1627906976744187 0.46511627906976744 0.9302325581395349)
We may be interested in how far values in a list are from some value. Let’s call the skewness the value that you get when you (a) compute the positive difference of every value in the list from the min; (b) find the geometric mean of all non-zero differences; (c) compute the positive difference of every value in the list from the max; (d) find the geometric mean of all non-zero differences; and (e) add the two geometric means together. Write a procedure to compute the skewness of a list. Then find a list that has a high skewness and a list that has low skewness. What does skewness seem to represent?
Write a comprehensive set of tests for parts A and C of problem 1. We will use your tests on incorrect versions of the code, to see if your tests catch the errors. Use comments to group tests together and to give any other helpful contextual information.
Sometimes students (and professors) come up with difficult-to-read solutions to arithmetic problems, like the one below.
(define hamster (lambda
(cat dog) (- (/ (+
(min cat dog) (max
cat dog)) 2) (min
cat dog))))
Add (or remove) carriage returns and indent the code so that it is formatted clearly.
Rename the procedure and the parameters so that they will make sense to the reader.
Write 151-style documentation for the code.
Submit lists-and-style.scm to Gradescope.
In grading your submission, we will look for the following at each level. Note that if a criteria does not pass a lower level, we will likely not check for criteria at the higher levels. We may also identify other characteristics that move your work between levels.
You should read through the rubric and verify that your submission meets the rubric.
Submissions that lack any of these characteristics will get an I.
[] Includes the specified file (correctly named).
[] Includes an appropriate header on the file that indicates the course, author, acknowledgements, etc.
[] Acknowledges appropriately.
[] Code runs in scamper.
Submissions that lack any of these characteristics but have all of the prior characteristics will get an R.
[] Code is well-formatted with appropriate names and indentation.
[] Code submission is organized with comments to indicate the start of new problems.
[] All Gradescope tests pass for Problem 1.
[] In problem 1, correct description of skewness is given.
[] In problem 2, given test cases catch all errors.
[] In problem 3, code is well formatted with better naming conventions.
[] Documentation in the 151 style is included for all code in Problem 1, and contains correct information.
[] Documentation in the 151 style is included for Problm 3, and contains correct information.
Submissions that lack any of these characteristics but have all of the prior characteristics will get an M.
[] All code is exceptionally organized and easy to read, through the use of comments (to explain the purpose of different pieces of the code) and decomposition.
[] Helper functions are used in a way to avoid replicating code in multiple places.