This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
cs330_f2016:racketlists [2018/09/11 16:23] morse |
cs330_f2016:racketlists [2018/09/13 22:07] morse |
||
---|---|---|---|
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 functions that use or return indices, such as ''index-of'' or ''list-ref''. | 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 58: | Line 61: | ||
For example, ''(convert (list 1 2 3))'' should return the number 321. | For example, ''(convert (list 1 2 3))'' should return the number 321. | ||
+ | |||
+ | For your own learning, try not to write this using ''string->number''. In fact, don't use strings at all--try to do the calculation mathematically. For semesters after F18, this will not be allowed. | ||
=== duple === | === duple === | ||
Line 73: | Line 78: | ||
(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 5/2. | For example, ''(average (list 1 2 3 4))'' returns 5/2. | ||
Line 94: | Line 99: | ||
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 === |