Coding Challenge 3: Working with the big three

Assigned
Monday, 9 February 2026
Summary
In this coding challenge we are getting comfortable with list manipulation, especially using map, reduce, and filter
Collaboration
Normal collaboration policies for coding challenges apply to this assignment. See the syllabus for specifics.

Instructions

In this coding challenge we are providing you with starter code, CC3-template.scm. You should download this file and upload the given code to a new .scm file named LASTNAME-big-three.scm, where you replace LASTNAME with your own last name.

At the top of your file, make sure to include your name, and any acknowledgements according to our collaboration policy. In that vein, now is a great time to review those collaboration policies!

Below that header, you’ll notice that there is a list of cities. You should be able to toggle to hide the list while you’re coding, as needed. You can use this list when testing your solution(s) to problem 3.

Problem 1: Removing Characters from Strings

Consider the problem of removing certain characters from a string. For example, perhaps we want to remove exclamation points from text in an email we are writing, to make the language sound more “professional”.

> (string-remove "Hello!! I'm happy to talk to you!" #\!)
"Hello I'm happy to talk to you"

Implement a procedure called string-remove which removes all instances of a character from a given string. You may find the procedure string-split helpful.

Here are some more examples of how the procedure should work.

>(string-remove "Hello!Goodbye" #\!)
"HelloGoodbye"
>(string-remove "Forward and Backward" #\a)
"Forwrd nd Bckwrd"
>(string-remove "And then there were none, by Agatha Christie" #\A)
"nd then there were none, by gatha Christie"

Problem 2: Lists of cycles

Part A

Use map to write a procedure (cycle n k) that outputs a list of n elements that only consist of the numbers 0…k-1 in ascending order. If n is greater than k then the list starts over from 0 after the kth element.

For example,

> (cycle 15 4)
(0 1 2 3 0 1 2 3 0 1 2 3 0 1 2)
> (cycle 10 3)
(0 1 2 0 1 2 0 1 2 0)
> (cycle 6 6)
(0 1 2 3 4 5)
> (cycle 11 2)
(0 1 0 1 0 1 0 1 0 1 0)

Part B (Optional)

Can you do part A without using map? Complete this part for a grade of “Exceeds Expectations”.

Part C

Using your procedure from Part A, write a procedure (cycle-char n) that returns a list of the first n characters of the alphabet. If n > 26 the sequence starts over.

For example,

> (cycle-char 5)
(#\A #\B #\C #\D #\E)
> (cycle-char 26)
(#\A #\B #\C #\D #\E #\F #\G #\H #\I #\J #\K #\L #\M #\N #\O #\P #\Q #\R #\S #\T #\U #\V #\W #\X #\Y #\Z)
> (cycle-char 30)
(#\A #\B #\C #\D #\E #\F #\G #\H #\I #\J #\K #\L #\M #\N #\O #\P #\Q #\R #\S #\T #\U #\V #\W #\X #\Y #\Z #\A #\B #\C #\D)

Problem 3: Filtering without filter

Part A

To start this problem, we are going to remove negative numbers from a list of numbers. Instead of using the filter procedure, we’ll use the following technique:

  • Add a 0 to the front of the list (add 0 to the front of lst with (cons 0 lst) )
  • Sort the list
  • Find the index of the 0
  • Drop everything up to that 0

Implement remove-negatives so that it behaves in the following way.

> (remove-negatives (list 1 4 -7 14 12 5 -3 -2 12))
(1 4 5 12 12 14)
> (remove-negatives (list -5 -4 -3 -2 -1 0 1 2 3 4 5))
(0 1 2 3 4 5)
> (remove-negatives (list 4 5 5 9 -2 -2.5 4.2 -2.5))
(4 4.2 5 5 9)

Part B

Write a procedure len-comp which takes in two strings as inputs, and returns #t if the length of the first string is less than the length of the second string. If the length of the two strings are equal, it should return #t if the first string comes alphabetically before the second string. The procedure returns #f in all other cases.

> (len-comp "Boise" "Des Moines") 
#t
> (len-comp "Boise" "Dover") 
#t
> (len-comp "Dover" "Boise")
#f 

Part C

Implement a procedure called remove-long-names using the technique from Part A as well as procedure you wrote in Part B. remove-long-names takes a list of strings and a number as input. The number is the longest length of string that should be in the output. That is, remove-long-names should output all the names from the list that are the length of the provided number or shorter.

The exact steps might not be identical to those in Part A, but you should use the strategy of adding something to the list and sorting it. You may not use filter in this solution.

(define cities
(list "Montgomery"
  "Juneau"
  "Phoenix"
  "Little Rock"
  "Sacramento"
  "Denver"
  "Hartford"
  "Dover"
  "Tallahassee"
  "Atlanta"
  "Honolulu"))
> (remove-long-names cities 5)
("Dover")
> (remove-long-names cities 6)
("Dover" "Denver" "Juneau")

Part D

Finally, write a procedure remove-long-names-filter which has the same objective as Part C, but uses the filter procedure. Use an anonymous procedure as input to filter.

Note: Your solution to part D will likely not return a sorted list. That is expected.

Submission guidelines

Submit your .scm file to Gradescope, using the name according to the top of these instructions.

Grading rubric

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.

Redo or above

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.

Meets expectations or above

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 grader tests pass for Problem 1.
[] Problem 2C makes calls to the procedure in problem 2B.
[] All grader tests pass for Problem 3, parts A, C, and D.
[] Problems 3A and 3C do not use `filter`. 
[] Problem 3D uses an anonymous procedure.

Exemplary / Exceeds expectations

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)
[] In problem 2B, `map` is not used
[] All grader tests pass for problem 2B.