---
# System prepended metadata

title: Homework 2 Additional Problem
tags: [conditionals, homeworks]

---

###### tags: `conditionals` `homeworks`

# Homework 2 Additional Problem

## Setup and Handin
### Setup
* Write your answers for this problem in a new file.
* Do **not** put your name anywhere in any file.

### Handin
* Make sure your file is called `hw2-extra.arr`. Hand in your work on Google Classroom. There is a separate assignment location than the assignment location for the rest of Homework 2.
* We will be taking a look at your handin and possibly providing light feedback, but there is no explicit rubric. In order to assess how you did, check out some potential solutions on Canvas. These will be posted within the next day or two.

## The Additional Problem
When we use a search engine, ads related to those searches sometimes appear in the same window. That suggests that the content of our search terms (also known as “queries”) might be used to select ads. For this problem, you will work with a simple version of this setup.

Assume that an ad is an arbitrary String and that a query can have up to three words (such as “bike”, “store”, “providence”). We want to rate an ad for how well it fits these three words. We will score each word against the ad. A word contributes a score of 1 if it (or a simple modification to it) appears in the ad; otherwise it contributes 0. The rating for an ad against the whole query is the sum of the ratings for each of the three query words divided by the length of the ad String (in characters).

For this question, we will consider modifications that make a word singular (by removing an “s” from the end, e.g. `"helmets"` -> `"helmet"`) or turn a gerund into a verb (by removing “ing” from the end, e.g. `"skateboarding"` -> `"skateboard"`). This means that any of the query words can score against an ad with or without an ending removed.

**Task:** Complete the following function:

```
fun rating(ad :: String, 
    wd1 :: String, wd2 :: String, wd3 :: String) -> Number:
 ...
end
```

Your work should emphasize two skills:

* How to structure your code. The computation itself is less important than how you organize your code (using named computations, helper functions, etc).
* A set of good examples for any functions you write for this problem.

This question doesn’t earn any points. It is meant to let you fine-tune your skills at structuring code and developing good sets of examples to illustrate a problem.