On this page:
1 Directions for submitting
2 Oveview
3 Lists of numbers
4 List of strings
5 Lists of positions
6.12

Exercise 5

Due: Wednesday, July 17, 11:59:59 PM EST.

Implement these exercises with the Beginning Student Language.

1 Directions for submitting

Please read and follow these intructions carefully. You should submit a single file named ex5.rkt on ELMS. You may submit many times, but each submission should be one file called ex5.rkt. You may lose points for not following these instructions.

Make sure the top of the file contains the following, with your name filled in:
;; Exercise 5
;; Name: ...your name here...

2 Oveview

The goal of this exercise is to practice using the “design recipe” for systematic problem solving with lists.

In this exercise, you will develop functions for operating on arbitrarily large collections of data. There are many problems, but practicing the design process will help make them go quickly.

3 Lists of numbers
;; A LoN (list of numbers) is one of:
;; - '()
;; - (cons Number LoN)

Problem 1: lon-count : LoN -> Natural

Count the number of elements in a given list of numbers.

Problem 2: lon-product : LoN -> Number

Compute the product of the given list of numbers (multiply all numbers together).

Problem 3: lon-add1-all : LoN -> LoN

Add one to every element of a given list and collect the results as a list.

Problem 4: lon-abs-all : LoN -> LoN

Compute the absolute value of every element of a given list and collect the results as a list.

Problem 5: lon-filter-even : LoN -> LoN

Produce a list that contains only the even elements of a given list.

Problem 6: lon-all-odd? : LoN -> Boolean

Determine if every element of a given list is odd.

4 List of strings
;; A LoS (list of strings) is one of:
;; - '()
;; - (cons String LoS)

Problem 7: los-count : LoS -> Natural

Count the number of elements in a given list of strings.

Problem 8: los-string-append : LoS -> String

Append together all the strings in a given list of strings.

Problem 9: los-upcase-all : LoS -> LoS

Capitalize every string in a given list and collect the results as a list. (Hint: string-upcase.)

Problem 10: los-length-all : LoS -> LoN

Compute the length of every string in a given list and collect the results as a list (of numbers).

Problem 11: los-filter-contains-e : LoS -> LoS

Produce a list that contains only the elements of a given list that contain the letter "e". (Hint: string-contains?.)

Problem 12: los-any-whitespace? : LoS -> Boolean

Determine if any element of a given list is whitespace. (Hint: string-whitespace?.)

5 Lists of positions
;; A LoP (list of positions) is one of:
;; - '()
;; - (cons Posn LoP)
 
;; A Posn is a (make-posn Number Number)

Problem 13: lop-count : LoP -> Natural

Count the number of elements in a given list of positions.

Problem 14: lop-dist-sum : LoP -> Number

Compute the sum of each position’s distance to the origin in a given list.

Problem 15: lop-dist-all : LoP -> LoN

Compute a list of distances to the origin for a given list of positions.

Problem 16: lop-change-x : LoP Number -> LoP

Change each position’s x-coordinate by given amount.

Problem 17: lop-remove-y-bound : LoP Number -> LoP

Produce a list that contains only the elements whose y-coordinate is between 0 (inclusive) and the given number (inclusive).

Problem 18: lop-any-equal? : LoP Posn -> Boolean

Determine if any element of a given list is the same as given position.