Coding Challenge 2: Writing Procedures

Assigned
Friday, 12 September 2025
Summary
In this coding challenge you will write your own procedures that rely heavily on booleans, predicates, and conditionals.
Collaboration
You must work individually on this assignment. You may only consult members of the course staff for help.

Instructions

In this coding challenge you should create a file called writing-procedures.scm which will contain all of your answers and code for this assignment. Use comments to organize your file so it’s easily read by a human.

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!

If a problem asks for a written response as an answer, use a comment to include it in your code file. Make sure to name definitions exactly as prescribed in the problems.

Problem 1: Categorizing words

There are a number of ways to categorize words. They may be short or long. They may start with or contain certain letters. They may contain repeated letters. They may be near other words. They may be common. They may be uncommon.

First, Pick and describe between six and ten categories. Then, write a procedure, (categorize-word word), that gives the category for a word as a string. You should use “uncategorized” for words that do not fit into your categories. For example,

> (categorize-word "aardvark")
"starts with vowel"
> (categorize-word "Grinnell")
"proper-name"
> (categorize-word "elephant")
"starts-with-vowel"
> (categorize-word "me")
"short"
> (categorize-word "hello")
"uncategorized"

If a word falls into multiple categories, you will pick only one. Be creative with your choice of categorization!

Problem 2: Median of three

We have seen a number of different ways to conditionally execute Scheme code in this course. For this problem, you will use three different techniques to implement a procedure that finds the median of three values. You will first write documentation for a median3 procedure that should apply to all of your implementations. Consider the following example uses of median3:

> (median3 1 3 2)
2
> (median3 -100 5 6)
5
> (median3 3 3 4)
3
> (median3 15.6 19.2 128)
19.2
> (median3 19 2 145)
19

You will implement this procedure three different ways: using if, using cond, and finally using short-circuit evaluation. Your implementations may only use numeric constants, lambda, and, or, not, <, <=, =, >=, >, +, and - unless otherwise specified below.

a. Write the procedure (median3-if x y z), which should find the median of three values using at least one if. In addition to the if expression(s), you may only use the procedures and syntax listed above.

b. Write the procedure (median3-cond x y z), which should find the median of three values using cond. In addition to the cond expression(s), you may only use the procedures and syntax listed above.

c. (For an E grade - updated Monday September 15) Write the predicate (strictly-between-any? x y z), which should return #t if one of the three values is strictly between the other two. Otherwise it should return false. You may not use if or cond, only use the procedures and syntax listed at the top of this problem.

Note: A previous version of this problem asked you to write (median3-short-circuit x y z), without using if or cond. While this is possible, it doesn’t get to the heart of boolean logic.

Submission guidelines

Submit writing-procedures.scm to Gradescope.

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 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.

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.
[] In problem 1, 6-10 categories are described and executed as described.
[] In problem 1, helper procedures are used to organize the code.
[] In problem 2, `median3-cond`	does not use `if`.
[] In problem 2, `median3-if` does not use `cond`.
[] In problem 2, `median3-if` and `median3-cond` pass all Gradescope tests.

Exemplary / Exceeds expectations

Submissions that lack any of these characteristics but have all of the prior characteristics will get an M.

[] In problem 1, categories are especially unique, or code is especially elegant.
[] In problem 2, `strictly-between-any?` passes all Gradescope tests.
[] In problem 2, `strictly-between-any?` does not use `if` or `cond`.