---
# System prepended metadata

title: Practice Problems on Lists and Datatypes
tags: [' 2022', Extras]

---

---
tags: Extras, 2022
title: Practice Problems on Lists and Datatypes
---

## Practice Problems with Lists and Datatypes

Remember the basic pattern of a recursive function:

```
fun my-func(alist :: List):
  cases (List) alist:
    | empty => ...
    | link(fst, rst) => ... my-func(rst) ...
  end
end
```

You can solve all of these by filling in the details within this basic pattern.

**Problem 1:** Write a function `sum-small` that adds up all the numbers that are smaller than 10 from a list.

**Problem 2:** Write a function `concat-firsts` that takes a list of strings and returns a `String` made by concatenating the first letter in each of the input strings (e.g., `concat-firsts([list: "go", "brown", "bears"]) is "gbb"`).

**Problem 3:** Write a function `count-has-z` that takes a list of strings and returns the number of strings that contain the letter `"z"`.

**Problem 4:** Write a function `stack-images` that takes a list of images and stacks them one on top of the other.

**Problem 5:** (bit more challenging) Write a function `combine-images` that takes a list of images and combines them into one image. When an image is more tall than wide, it gets put besides other images; when it is more wide than tall, it gets put on top of other images. Use `image-width` and `image-height` to compute the width and height of images.

**Problem 6:** Imagine that we had the following data block for email messages:

```
data Email: 
  message(
    sender :: String, 
    recipient :: String, 
    content :: String, 
    been-read :: Boolean)
end
```

Assume that an inbox is a list of messages. Write a function `count-unread` that takes an inbox and input and counts the number of messages that have been read.

**Problem 7:** Now write a function `get-unread` that takes an inbox and returns a list with only the unread messages. Write this two ways, once with built-in functions and once with manual recursion.




