|
You should print out your solutions to this assignment, and either turn them in at lecture, or leave them in the TA's mailbox at Sudikoff by class time on Mon. Sep. 28, 2009.
Please also e-mail an electronic version of your code to cs8hw@cs.dartmouth.edu, with the subject "CS 8 Short Assignment 1". Please attach your code as one or more enclosures to the message, and do not include it directly in the body of the e-mail message.
You must work alone on this short assignment.
Write a function computeSquares that takes a list
of Doubles and returns a list of the squares of the numbers
in the list. Thus computeSquares [1.0, 2.0, -3.0] =>
[1.0, 4.0, 9.0] Do this using a higher-order function,
not recursion.
Write a function distance that finds the distance
between two n-dimensional points, where the points are represented
as lists of their coordinates. The coordinates are represented as
Doubles. Thus to find the distance between the points
(1, 0, 0) and (0, 1, 0) you should call
distance [1.0, 0.0, 0.0] [0.0, 1.0, 0.0]
While good style would usually be to define helper functions
(e.g. listSum), I want you to do this as a "one-liner"
using a subset of the four higher-order functions that we have
seen. You also may use the sqrt function.
Do exercise 5.9 on p. 73. Your function should always use as
many coins of a given size as possible before moving on to the
next coin size in the list. Thus
makeChange 80 [25, 10, 5, 1] => [3, 0, 1, 0].
Solve this problem using recursion.
Write the functions takeEvens and takeOdds. Given a list of Integers, takeEvens should return the items in the 0th, 2nd, 4th, etc. positions and takeOdds should return the items in the 1st, 3rd, 5th, etc. positions. Thus
takeEvens [1, 2, 3, 4] => [1, 3]
takeEvens [1] => [1]
takeEvens [] => []
takeOdds [1, 2, 3, 4] => [2, 4]
takeOdds [1] => []
takeOdds [] => []
Solve this problem using recursion.
Home Page |
Announcements |
Course Info |
Materials |
Software |
Department of Computer Science, Dartmouth College, Hanover, New Hampshire, USA
Last modified: 12-August-2009