Due Date | Language | Problems |
---|
11/31 | Intermediate Student w/lambda | Do exercises 31.3.3, 31.3.4, and 31.3.7 from HtDP using foldl (the accumulator version of fold).
;; foldl : (listof X) Y (X Y -> Y) -> Y (define (foldl l a combine) (cond [(empty? l) a] [else (foldl (rest l) (combine (first l) a) combine)]))
|
11/24 | Intermediate Student w/lambda | HtDP: 31.3.4, 31.3.6, 31.3.7 |
11/22 | Intermediate Student w/lambda | Write the function reverse from earlier in class. It takes a list of numbers and returns the same list, but in the reverse order.
This function suffers from the same flaw as the food-chain function in lecture. Rewrite it using an accumulator to fix the problem.
Write the product function using an accumulator (it takes a list of numbers and returns their product). |
11/19 | Intermediate Student w/lambda | HtDP: 14.4.1, 14.4.2, 14.4.3 |
11/12 | Intermediate Student w/lambda | HtDP: 25.2.2, 25.2.3, 25.2.4 |
11/10 | Intermediate Student w/lambda | A small boy decides to climb the 10ft tall tree in his front yard. The tree has one branch each foot. As the boy climbs the tree, one of these three things happens (at each branch): - he falls off the tree, with a 1:100 chance;
- he gets scared and decides to climb down one branch;
- he continues climbing;
The boy gets scared with a chance 1 in z*2 if he is z feet from the top of the tree. If the boy gets scared when he's on the ground, he gives up.
Write a function that models the boy's behavior as he climbs the tree ;; climb-tree : number -> 'made-it 'scared-down or 'fell-off (define (climb-tree height) ...)
Test your function by putting several calls to it (with 0 as an argument) in the bottom of the definitions window, since it won't always return the same result.
Here is a useful helper function: ;; 1-in-X-chance : Nat -> boolean ;; returns true randomly, with odds 1:X ;; That is, 1-in-X-chance always returns true if x is 1 ;; 1-in-X-chance returns true half of the time if X is 2, etc. (define (1-in-X-chance x) (zero? (random x)))
|
11/8 | Intermediate Student w/lambda | Html exercises 1.1 - 1.3 |
11/3 | Intermediate Student w/lambda | a) Hand evaluate: (show all steps)
(define mul (lambda (x) (lambda (y) (* x y)))) (define m3 (mul 3)) (+ (m3 3) (m3 4))
b) Hand evaluate: (show only recursive calls)
(map (lambda (x) (expt x 3)) (list 1 2 3))
b) Hand evaluate: (show only recursive calls)
(filter (lambda (x) (zero? (modulo x 3))) (list 5 6 7))
If you don't know what some of the primitives above do, try them out in the interactions window. |
11/1 | Intermediate Student | Define the following functions in terms of fold, filter, or map:
; double-each : list-of-numbers -> list-of-numbers ; to double each of the elements in alon (define (double-each alon) ...)
; keep-perfect-sq : list-of-numbers -> list-of-numbers ; to remove each non-perfect square from alon (define (keep-perfect-sq alon) ...)
; sum-of-squares : list-of-numbers -> number ; to sum up the squares of all the numbers in alon (define (sum-of-squares alon) ...)
; howmany : list-of-list-of-numbers -> number ; to count the number of numbers in alolon (define (howmany alolon) ...)
; example as test (howmany (list (list 1 2 3) (list 4 5 6) (list 7 8 9))) 'shouldbe 9
Recall family trees: ; a ft is either: ; - 'unknown ; - (make-node ft ft symbol number) (define-struct node (mom dad eyes year))
Define the fold function for family trees (based on the template) and re-define blue-eyed-ancestor? : ft -> boolean in terms of the new fold function.
If you define any recursive helper functions, be sure to use fold, filter or map for them (if possible). |
10/27 | Intermediate Student | Consider the data definition and template for non-empty list of images: ; a non-empty-list-of-images is either ; - (cons image empty) ; - (cons image non-empty-list-of-images
;; neloi-template : non-empty-list-of-imges -> ??? (define (neloi-template a-neloi) (cond [(empty? (rest a-neloi)) ... (first a-neloi) ...] [else ... (first a-neloi) ... ... (neloi-template (rest a-neloi)) ...])) (See the exam sample solution for an example function using this data definition and template.)
Write best-image:
; best-image : (image image -> boolean) non-empty-list-of-images -> image ; to find the best image, according to the predicate, pred (define (best-image pred a-neloi) ...)
Using best-image write the following functions:
; narrowest-image : non-empty-list-of-images -> image ; to find the image with the smallest width
; biggest-image : non-empty-list-of-images -> image ; to find the image with the largest area
; darkest-image : non-empty-list-of-images -> image ; to find the image with the lowest average color component ; (considering all three color components in each color)
Don't forget: helper functions! |
10/25 | Intermediate Student | Write the function: ; reverse : list-of-numbers -> list-of-numbers ; reverses the elements in a-lon (define (reverse a-lon) ...)
using the helper function:
; add-at-end : number list-of-numbers -> list-of-numbers ; to produce a list of numbers with the elements of a-lon followed by n (define (add-at-end n a-lon) ...)
Combine those two functions into a single function, using local so that add-at-end can only be called by reverse.
Write the function: ; max : list-of-numbers -> max ; to determine the biggest element in a-lon, ; assuming that all elements are positive (define (add-at-end n a-lon) ...)
without using a helper function, but use local to avoid repeated computation in the body. |
10/22 | Beginning Student w/List Abbreviations | Finish the lab. (Only do refinement 1, skip the rest.) |
10/15 | Beginning Student w/List Abbreviations | Write the function (and assocated helper functions): ; find : dir string -> boolean ; to determine if a file with the content `content' is in `dir' ; (the content must match exactly) (define (find a-dir content) ...) Useful helper function: string=? : string string -> boolean. It determines if two strings match exactly. Don't forget: strings are written like this: "abcdef".
Adapt the data definition from class to support files that have permissions. A file's permissions should be one of 'read-write 'read-only 'write-only.
Adapt your find function to only search in files that can be read.
Here is the final data definition from class. ; a file is: ; - (make-file symbol string) ; ; a dir-content is either: ; - empty ; - (cons file dir-content) ; - (cons dir dir-content) ; ; a dir is: ; - (make-dir name dir-content) (define-struct file (name content)) (define-struct dir (name content))
|
10/13 | Beginning Student w/List Abbreviations | Write the following functions. ; a ftn is either ; - 'unknown, or ; - (make-child symbol number symbol ftn ftn) (define-struct child (name date eyes mom dad))
; 40-year-old-ancestor? : ftn -> boolean ; to determine if a 40-year-old ancestor is in a-ftn (define (40-year-old-ancestor? a-ftn) ...)
; count : ftn -> number ; to count the number of people in a-ftn (define (count a-ftn) ...)
|
10/11 | Beginning Student w/List Abbreviations | Images: 4.1 - 4.3 |
10/8 | Beginning Student | Write the following functions. Don't forget about re-use and helper functions (the functions we wrote in class are fair game for re-use as helper functions). ; a list-of-symbols is either ; - empty, or ; - (cons symbol list-of-symbols)
; contains-doll? : list-of-symbols -> boolean ; to determine if 'doll appears in alos (define (contains-doll? alos) ...)
; a list-of-numbers is either ; - empty, or ; - (cons number list-of-numbers)
; len : list-of-numbers -> number ; to determine the number of elements in alon (define (len alon) ...)
; avg : list-of-numbers -> number ; to determine the average of the elements in alon (define (avg alon) ...) |
10/6 | Beginning Student | HtDP: 7.2.2 (make sure all vehicles have wheels)
Develop the function toll : vehicle -> number. It determines the amount a vehicle must pay at a toll. The toll costs $0.50 per wheel.
Extend the animal data definition from class with one new kind of animal. Make sure the new animal has a weight.
Write a template for the extended animal data definition.
Write the function diet : animal -> animal. It accepts an animal and returns the same animal, but with half of the weight. |
10/4 | Beginning Student | Write the function dist-to-0 : posn -> number that determines how far a posn is from the origin. HtDP: 6.3.1 (1, no box drawing), 6.4.1(1), 6.5.1(1) |
10/1 | Beginning Student | Images: 2.1 - 2.3 |
9/29 | Beginning Student | HtDP: 2.2.5 Images: 1.1 - 1.5 |