CS 1410-20 Homework 4-default

Due: Friday, September 24th, 2010 9:40am

Part 1 – Snoc

Implement snoc, which takes a list of numbers and a number, and returns a list like the given one but with the given number added to the end of the list (hence the name “snoc,” which is “cons” backwards).

Part 2 – Only-Smaller

Implement only-smaller, which takes a number n and list of numbers, and it returns a list like the given one, but with all numbers n or larger removed.

For example, (only-smaller 2 (list 1 2 3 0)) should produce (list 1 0).

Part 3 – Total-Distance

Implement total-distance, which takes a list of posns and returns the sum of all posn distances from the origin (where each distance is computed as the crow flies).

Part 4 – Averge-Distance

Implement average-distance, which takes a list of posns and returns the average distance of the posns from the origin.

You can use the pre-defined length function, which takes any list and returns the number of items in the list.

Part 5 – Party

You’ve invited a freinds for a party, and you need to keep track of who’s coming. Each invitation names several people (usually a family), and anyone on a invitation can RSVP for everyone on the same invitation.

Design a data structure for keeping track of an invitation. Each invitation should have a list of people, where each person is represented by a string. An invitation should also reflect whether anyone has RSVPed for that particular invitation.

Implement rsvp, which takes a list of invitations and a string, where the string is a person’s name. It returns a list of invitations like the given one, except that the invitaton with the named person is marked as RSVPed. (You can assume that all people across all invitations have different names.)


Last update: Wednesday, October 20th, 2010
mflatt@cs.utah.edu