### Lecture 19: Follow the template

This assignment is due on Sunday, March 17 at 11:59pm. Submit it using Handin as assignment lecture19. You only need to submit the first 2 exercises.

#### 1` `Midterm advice

Read every word of instructions.

Define everything you use.

Solve old problems, including those on the first midterm and before. Students who don’t review that basic material are often surprised by how poorly they do on the second midterm.

Feel free to ask questions, like on Discord!

#### 2` `Pre-landing check

Check your answer using “Show answer” above. Did you get it right? If not, click the button again to get another set, and keeping doing it until you get it right without peeking at the answer.

You don’t need to submit anything for this check.

#### 3` `Follow the template and make a wish

Exercise 1. To review what we’ve learned, let’s design a function our-sort to sort a list of numbers into ascending order. Do steps 1–4 of the design recipe: write the template meticulously (named our-sort), but don’t fill it in (so when you run your program, your tests should fail with the error expected a finished expression, but found a template).

Exercise 2. We wish we could just fill in the template by replacing the dots with the name of a helper function. Design the function insert which takes a Number and a ListOfNumbers and puts the number in the correct place in the list, assuming the list is already sorted. The new number should go before all the numbers bigger than it, and after all the numbers smaller than it. Don’t use the built-in sort function.

#### 4` `More midterm review

For the rest of this page, you don’t need to submit anything.

Exercise 3. Recall the data definition of Mobile from Problem set 6: Unions and recursion. Design the function count-leaves which counts how many leaves are in a given Mobile.

Exercise 4. Design the function count-big-leaves which counts how many leaves of weight more than 10 are in a given Mobile.

Exercise 5. Design a function remove-multiples-of-10 that removes every number divisible by 10 from a list of numbers. Use filter.

Hint: Study the signature and purpose of filter in Figure 95 of the textbook. What is X?

Exercise 6. Design a function has-multiple? that takes a list of numbers and a number as inputs, and checks whether any number in the given list is a multiple of the given number. Use ormap.

Hint: Study the signature and purpose of ormap in Figure 95 of the textbook. What is X?

Exercise 7. Design a function move-invaders which takes a list of Posns and increases each Y coordinate by 1. Use map.

Hint: Study the signature and purpose of map in Figure 95 of the textbook. What is X and what is Y?