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 foodchain 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 ;; climbtree : number > 'madeit 'scareddown or 'felloff (define (climbtree 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: ;; 1inXchance : Nat > boolean ;; returns true randomly, with odds 1:X ;; That is, 1inXchance always returns true if x is 1 ;; 1inXchance returns true half of the time if X is 2, etc. (define (1inXchance 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:
; doubleeach : listofnumbers > listofnumbers ; to double each of the elements in alon (define (doubleeach alon) ...)
; keepperfectsq : listofnumbers > listofnumbers ; to remove each nonperfect square from alon (define (keepperfectsq alon) ...)
; sumofsquares : listofnumbers > number ; to sum up the squares of all the numbers in alon (define (sumofsquares alon) ...)
; howmany : listoflistofnumbers > 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 ;  (makenode ft ft symbol number) (definestruct node (mom dad eyes year))
Define the fold function for family trees (based on the template) and redefine blueeyedancestor? : 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 nonempty list of images: ; a nonemptylistofimages is either ;  (cons image empty) ;  (cons image nonemptylistofimages
;; neloitemplate : nonemptylistofimges > ??? (define (neloitemplate aneloi) (cond [(empty? (rest aneloi)) ... (first aneloi) ...] [else ... (first aneloi) ... ... (neloitemplate (rest aneloi)) ...])) (See the exam sample solution for an example function using this data definition and template.)
Write bestimage:
; bestimage : (image image > boolean) nonemptylistofimages > image ; to find the best image, according to the predicate, pred (define (bestimage pred aneloi) ...)
Using bestimage write the following functions:
; narrowestimage : nonemptylistofimages > image ; to find the image with the smallest width
; biggestimage : nonemptylistofimages > image ; to find the image with the largest area
; darkestimage : nonemptylistofimages > 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 : listofnumbers > listofnumbers ; reverses the elements in alon (define (reverse alon) ...)
using the helper function:
; addatend : number listofnumbers > listofnumbers ; to produce a list of numbers with the elements of alon followed by n (define (addatend n alon) ...)
Combine those two functions into a single function, using local so that addatend can only be called by reverse.
Write the function: ; max : listofnumbers > max ; to determine the biggest element in alon, ; assuming that all elements are positive (define (addatend n alon) ...)
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 adir 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 'readwrite 'readonly 'writeonly.
Adapt your find function to only search in files that can be read.
Here is the final data definition from class. ; a file is: ;  (makefile symbol string) ; ; a dircontent is either: ;  empty ;  (cons file dircontent) ;  (cons dir dircontent) ; ; a dir is: ;  (makedir name dircontent) (definestruct file (name content)) (definestruct dir (name content))

10/13  Beginning Student w/List Abbreviations  Write the following functions. ; a ftn is either ;  'unknown, or ;  (makechild symbol number symbol ftn ftn) (definestruct child (name date eyes mom dad))
; 40yearoldancestor? : ftn > boolean ; to determine if a 40yearold ancestor is in aftn (define (40yearoldancestor? aftn) ...)
; count : ftn > number ; to count the number of people in aftn (define (count aftn) ...)

10/11  Beginning Student w/List Abbreviations  Images: 4.1  4.3 
10/8  Beginning Student  Write the following functions. Don't forget about reuse and helper functions (the functions we wrote in class are fair game for reuse as helper functions). ; a listofsymbols is either ;  empty, or ;  (cons symbol listofsymbols)
; containsdoll? : listofsymbols > boolean ; to determine if 'doll appears in alos (define (containsdoll? alos) ...)
; a listofnumbers is either ;  empty, or ;  (cons number listofnumbers)
; len : listofnumbers > number ; to determine the number of elements in alon (define (len alon) ...)
; avg : listofnumbers > 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 distto0 : 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 