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 LASTNAME-style.scm, where you replace LASTNAME with your last name.
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)
(list 1 2 4 3 2 4)
Write a procedure, (scale-by-average lst), that divides every element of the list by the average value in the list. You may assume that the average value will not be 0.
> (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)
Write a procedure middle-vals-average which takes in lst, a list of numbers, a, the number of smallest elements to drop, and b, the number of largest elements to drop, and then computes the average of the remaining values. For example a call of
(middle-vals-average (list -10 4 -1 300 -2.3 6 7.5) 3 2)
would require you to first remove the (3) smallest values and the (2) largest values from the list, and then return the average of the remaining values.
> (middle-vals-average (list -10 4 -1 300 -2.3 6 7.5) 3 2)
5
> (middle-vals-average (list -10 4 -1 300 -2.3 6 7.5) 1 2)
1.675
(Optional, needed for a grade of Exceeds Expectations)
Revise all of your solutions to parts A through C so that your solutions are extremely concise, and do not use any helper procedures. You may choose to use anonymous procedures and/or local bindings.
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 problems. Here is one such solution:
(define
:/ (lambda (
:) (map (o (section list-ref : _) (section - (length
:) _ 1)) (range (length
:) ))))
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, and so the type and purpose is clear.
Write 151-style documentation for the code.
Submit your .scm file to Gradescope, using the name according to the top of these instructions.
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 N.
[] 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 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 Problem 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 (when applicable).
[] Solutions to problem 1 are exceptionally concise (part D of problem 1)