User Tools

Site Tools


cs330_f2016:racketlists

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

cs330_f2016:racketlists [2016/08/31 18:49]
morse
cs330_f2016:racketlists [2021/06/30 23:42]
Line 1: Line 1:
-====Objective:​==== 
- 
-Learn the basics of the Racket lists and various patterns of recursion: 
-  * List operators 
-  * Natural recursion 
-  * Common patterns for recursive list-processing operations 
-  * Using auxiliary variables 
- 
----- 
- 
-====Preparation:​==== 
- 
-You will again use DrRacket, which you should have downloaded and installed for the previous lab. 
- 
----- 
- 
-====Deliverables:​==== 
- 
-For this lab, you will need to implement the following functions and data structures in Racket: 
-  * ''​check-temps1''​ 
-  * ''​check-temps''​ 
-  * ''​convert''​ 
-  * ''​duple''​ 
-  * ''​average''​ 
-  * ''​convertFC''​ 
-  * ''​eliminate-larger''​ 
-  * ''​get-nth''​ 
-  * ''​find-item''​ 
- 
-=== check-temps1 === 
-<code racket> 
-(define (check-temps1 temps) ...) 
-</​code>​ 
-where ''​temps''​ is a list of numbers representing temperatures and the result is a boolean indicating whether all of the temperatures are with the range 5 to 95 inclusive. 
- 
-For example, ''​(check-temps1 (list 80 92 56))''​ returns true, and ''​(check-temps1 (list 80 99 56))''​ returns false. 
- 
-=== check-temps1 === 
-<code racket> 
-(define (check-temps temps low high) ...) 
-</​code>​ 
-where ''​temps''​ is a list of numbers representing temperatures and the result is a boolean indicating whether all of the temperatures are with the range ''​low''​ to ''​high''​ inclusive. 
- 
-For example, ''​(check-temps some-list-of-temps 5 95)''​ should work just like ''​(check-temps1 some-list-of-temps)''​. 
- 
-Suggestion: Yes, you could code ''​check-temps1''​ to just call your more general ''​check-temps''​. But try to code ''​check-temps1''​ first to see the basic pattern, then think about how to generalize it to ''​check-temps''​. 
- 
-=== convert === 
-<code racket> 
-(define (convert digits) ...) 
-</​code>​ 
-where ''​digits''​ is a list of digits (each between 0 and 9) and the result is the integer equivalent of these interpreted as a list of digits of a number in reverse order.  ​ 
- 
-For example, ''​(convert (list 1 2 3))''​ should return the number 321. 
- 
-=== duple === 
-<code racket> 
-(define (duple lst) ...) 
-</​code>​ 
-where ''​lst''​ is a list of any type of values, and the result is a list of two-element lists that has each value duplicated.  ​ 
- 
-For example, ''​(duple (list 1 2 3))''​ returns the list ''​( (1 1) (2 2) (3 3) )''​. 
- 
-Hint: Be careful when to use ''​list''​ and when to use ''​cons''​. 
- 
-=== average === 
-<code racket> 
-(define (average lst) ...) 
-</​code>​ 
-where ''​lst''​ is a list of numbers, and the result is the average of these numbers. 
- 
-For example, ''​(average (list 1 2 3 4))''​ returns 2.5. 
- 
-=== convertFC === 
-<code racket> 
-(define (convertFC temps) ...) 
-</​code>​ 
-where ''​temps''​ is a list of numbers representing temperatures in Fahrenheit, and the result is a list representing the same values in Celsius.  ​ 
- 
-For example, ''​(convertFC (list 32 50 212))''​ returns ''​(0 10 100)''​. 
- 
-=== eliminate-larger === 
-<code racket> 
-(define (eliminate-larger lst) ...) 
-</​code>​ 
-where ''​lst''​ is a list of numbers, and the result is the same list but with all values larger than any subsequent ones removed.  ​ 
- 
-For example, ''​(eliminate-larger (list 1 2 3 9 4 5))''​ returns ''​(1 2 3 4 5)''​. 
- 
-Hint: try using a helper function. 
- 
-=== get-nth === 
-<code racket> 
-(define (get-nth lst n) ...) 
-</​code>​ 
-where ''​lst''​ is a list of arbitrary types and ''​n''​ is a non-negative number less than the length of the list, and the result is the nth item of the list using zero-based indexing.  ​ 
- 
-For example ''​(get-nth (list 1 2 3 4) 2)''​ returns the value 3. 
- 
-Note: You must code this recursively and not use any other built-in Racket functions for such indexing, nor can you simply convert it to a vector and then do random access. 
- 
-=== find-item === 
-<code racket> 
-(define (find-item lst target) ...) 
-</​code>​ 
-where ''​lst''​ is a list of numbers and ''​target''​ is a number, and the result is the position (using zero-based indexing) at which ''​target''​ first appears in the list, or -1 if it doesn'​t appear.  ​ 
- 
-For example, ''​(find-item (list 1 2 3 4) 3)''​ returns the value 2, and ''​(find-item (list 1 2 3 4) 42)''​ returns -1. 
- 
-Hint: consider using an auxiliary variable. 
- 
----- 
- 
-====Notes:​==== 
- 
-You again **do not** need to bulletproof the code to enforce proper inputs.  ​ 
-Your code only needs to return correct values given correct inputs. 
- 
----- 
- 
-====Hints:​==== 
- 
-You may want to again use the Step button to walk through your code and watch the equivalent sequence of substitutions that are performed. ​ This is particularly useful in tracing the recursion and watching what's happening to the parameters. 
  
cs330_f2016/racketlists.txt ยท Last modified: 2021/06/30 23:42 (external edit)