User Tools

Site Tools


cs330_f2016:racketlists

Differences

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

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
cs330_f2016:racketlists [2016/08/31 23:10]
dcostello
cs330_f2016:racketlists [2021/06/30 23:42] (current)
Line 30: Line 30:
 ** **
 You must write all of these functions recursively (though you can use helper functions as needed). You must write all of these functions recursively (though you can use helper functions as needed).
-You may not use higher-order functions like ''​map'',​ ''​filter'',​ or any of the variants of ''​fold''​.+ 
 +You may not use higher-order functions like ''​map'',​ ''​filter'',​ or any of the variants of ''​fold''​. You may not use functions that use or return indices, such as ''​index-of''​ or ''​list-ref''​. 
 + 
 +You may not use anything that modifies a value in place such as ''​set!''​ or list-modification operators.
 ** **
  
Line 55: Line 58:
 (define (convert digits) ...) (define (convert digits) ...)
 </​code>​ </​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.  ​+where ''​digits''​ is a non-empty ​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. For example, ''​(convert (list 1 2 3))''​ should return the number 321.
 +
 +You may not use ''​string->​number''​ or any other string-handling functions for this.  Avoid using strings at all.
 +
 +Hint: Don't try to figure out what position each digit is in as you process the list. (I.e., don't worry about "​hundreds place",​ "tens place",​ etc.). Can you figure out how to write the conversion with a more straightforward recursion? ​ What should recursing on the rest of the list return if the function works correctly? ​ What's the relationship between that and the first thing in the list that will give you the correct result?
  
 === duple === === duple ===
Line 73: Line 80:
 (define (average lst) ...) (define (average lst) ...)
 </​code>​ </​code>​
-where ''​lst''​ is a list of numbers, and the result is the average of these numbers.+where ''​lst''​ is a non-empty ​list of numbers, and the result is the average of these numbers.
  
-For example, ''​(average (list 1 2 3 4))''​ returns 2.5.+For example, ''​(average (list 1 2 3 4))''​ returns ​5/2. 
 + 
 +Hint: you are **not** required to compute the average in a single passCan you break it into simpler operations?
  
 === convertFC === === convertFC ===
Line 89: Line 98:
 (define (eliminate-larger lst) ...) (define (eliminate-larger lst) ...)
 </​code>​ </​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.  ​+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)''​. For example, ''​(eliminate-larger (list 1 2 3 9 4 5))''​ returns ''​(1 2 3 4 5)''​.
  
 Hint: try using a helper function. Hint: try using a helper function.
 +
 +Hint 2: consider trying to make the decision about whether to drop a particular item from the list **after** recursively calling eliminate-larger on the rest after that one -- it's easier.
  
 === get-nth === === get-nth ===
Line 121: Line 132:
 You again **do not** need to bulletproof the code to enforce proper inputs.  ​ You again **do not** need to bulletproof the code to enforce proper inputs.  ​
 Your code only needs to return correct values given correct inputs. Your code only needs to return correct values given correct inputs.
 +But you should be careful to think about what the correct output should be for the case where the input list is empty.
  
 ---- ----
Line 129: Line 141:
  
 You may use auxiliary or helper functions as needed. ​ For many of these the simplest solution is to use multiple functions instead of trying to cram it all through one recursive pass through the list.  You might also have to recurse through the list multiple times, in which case it's easiest to use separate functions. You may use auxiliary or helper functions as needed. ​ For many of these the simplest solution is to use multiple functions instead of trying to cram it all through one recursive pass through the list.  You might also have to recurse through the list multiple times, in which case it's easiest to use separate functions.
- 
  
  
cs330_f2016/racketlists.1472685029.txt.gz · Last modified: 2021/06/30 23:40 (external edit)