UNB/ CS/ David Bremner/ teaching/ cs2613/ labs/ Lab 6

# Questions

Time
5 Minutes
Activity
Group discussion / Announcments

# Setup

• make a directory `labs/L06` inside your `~/cs2613` git repository
• All of your work from today should be committed in that directory (and pushed before you leave).

# Structural recursion on two parameters

Time
35 minutes
Activity
Small groups
Summary
• Form a group of 2 or 3.

• Work together to design the template in FICS Exercise 17

• Individually implement the function `keep-first` which follows this template.

• Compare your functions. Are there any interesting differences?

• Here is a test case

``````  (check-expect (keep-first 3 (list 1 2 3 4)) (list 1 2 3))
``````

# Intersection of two ordered lists

Time
35 minutes
Activity
Individual work
Summary

Recall the template for structural recursion on two lists

```(define (my-list-fn lst1 lst2)
(cond
[(empty? lst1) ... lst2 ...]
[(empty? lst2) ... lst1 ...]
[(cons? lst1)
... (first lst1) ... (first lst2) ...
... (my-list-fn (rest lst1) lst2) ...
... (my-list-fn lst1 (rest lst2)) ...
... (my-list-fn (rest lst1) (rest lst2)) ...]))
```

Use this template to complete FICS Exercise 20 You may find it helpful to refer to the function `o-union` defined in Section 5.4

Here are some test cases for the function `intersection`

```(check-expect (intersection (list 1 2 3 4 5) (list 2 4 6 7))
(list 2 4))

(check-expect (intersection (list 2 4 11) (list 1 2 3 4 5))
(list 2 4))
```

# Generating all subsets of fixed size

Time
35 minutes
Activity
Individual work
Summary

Start with the template from the first exercise and complete FICS Exercise 24. If your template needs updating, compare with cases in the two list template.

Use the built-in function `append` and the function `cons-all` you wrote in Lab 5.

Here are some test cases to illustrate the use of the function `comb`

```(check-expect (comb '(a) 1) '((a)))
(check-expect (comb '(1 2) 1) '((1) (2)))
(check-expect (comb '(1 2 3) 2) '((1 2) (1 3) (2 3)))
```