a05-cs135-w10

a05-cs135-w10 - CS 135 Winter 2011 Brad Lushman Assignment:...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CS 135 Winter 2011 Brad Lushman Assignment: 5 Due: Friday, February 18, 9:30am Language level: Beginning Student with List Abbreviations Allowed recursion: Pure structural Files to submit: curling.rkt , index.rkt Warmup exercises: HtDP 12.2.1, 13.0.3, 13.0.4, 13.0.7, 13.0.8 Practise exercises: HtDP 13.0.5, 13.0.6, 17.1.1, 17.1.2, 17.2.1, 17.2.2 Here are the assignment questions you need to submit. 1. During Canadas long, cold winters, the mind of every Canadian is focused on a single sport: curling. In a game of curling, teams take turns sliding granite stones (rocks) across a sheet of ice towards a target at the other end of the sheet. Once all of the rocks have been thrown, the team whose rock is closest to the centre of the target scores a number of points equal to the number of their rocks that lie closer to the centre than their opponents closest rock. For example, in the following configuration, the team throwing the yellow rocks scores two points, since there are two yellow rocks closer to the centre than the closest red rock. To be eligible for scoring, a rock must at least make contact with the edge of the scoring area. For example, the red rock at the top of the diagram above could not score a point, even if there were no other rocks in the diagram. If there are no rocks at least touching the scoring area, no one scores. The scoring area is 6 feet in diameter, and if we assume that the rocks are 1 foot in diameter, then we conclude that the centre of the rock can be at most 6.5 feet from the centre of the scoring area in order to be considered for scoring. In this question, you will write a Scheme program to compute the score of an end of curling, given the positions of the rocks: CS 135 Winter 2011 Assignment 5 1 (a) Give a structure definition and a data definition for a rock structure, with fields colour , x , and y . The colour field should be either red or yellow . (b) Write the Scheme predicate closer? that consumes two rock s, and produces the answer true if and only if the first rock is closer to the centre than the second one. The centre of the scoring area has coordinates (0 , 0) (i.e., x = y = 0 ). Note: In order to avoid computations with inexact numbers, compare rocks based on the square of the distance from the centre, rather than on the actual distance from the centre. This is a valid simplification, since rock A is closer to the centre than rock B if and only if the square of the distance from rock A to the centre is less than the square of the distance from rock B to the centre. (c) Write the function sort-rocks that consumes a ( listof rock ) and sorts the rocks in the list by distance from the centre. Since this will be only a slight modification of code presented in class, you do not have to do the design recipe for this function....
View Full Document

Page1 / 6

a05-cs135-w10 - CS 135 Winter 2011 Brad Lushman Assignment:...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online