-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
162 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#lang racket | ||
|
||
(check-expect (extract < (cons 6 (cons 4 '())) 5) (list 4)) | ||
(check-expect (extract > (cons 6 (cons 4 '())) 5) (list 6)) | ||
|
||
(define (extract R l t) | ||
(cond | ||
[(empty? l) '()] | ||
[else (cond | ||
[(R (first l) t) | ||
(cons (first l) | ||
(extract R (rest l) t))] | ||
[else | ||
(extract R (rest l) t)])])) | ||
|
||
|
||
(extract < (cons 6 (cons 4 '())) 5) | ||
|
||
(extract < (cons 4 '()) 5) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#lang racket | ||
|
||
(check-expect (extract < (cons 6 (cons 4 '())) 5) (list 4)) | ||
(check-expect (extract > (cons 6 (cons 4 '())) 5) (list 6)) | ||
|
||
(define (extract R l t) | ||
(cond | ||
[(empty? l) '()] | ||
[else (cond | ||
[(R (first l) t) | ||
(cons (first l) | ||
(extract R (rest l) t))] | ||
[else | ||
(extract R (rest l) t)])])) | ||
|
||
(extract < (cons 8 (cons 4 '())) 5) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#lang racket | ||
(define (squared>? x c) | ||
(> (* x x) c)) | ||
|
||
|
||
(squared>? 3 10) | ||
|
||
(squared>? 4 10) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#lang racket | ||
|
||
(define (f x) x) | ||
|
||
(cons f '()) | ||
|
||
(f f) | ||
|
||
(cons f (cons 10 (cons (f 10) '()))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#lang racket | ||
|
||
(check-within (tabulate sin 5) (tab-sin 5) 0.000001) | ||
(check-within (tabulate sqrt 5) (tab-sqrt 5) 0.000001) | ||
|
||
(define (tabulate g n) | ||
(cond | ||
[(= n 0) (list (g 0))] | ||
[else | ||
(cons | ||
(g n) | ||
(tabulate g (sub1 n)))])) | ||
|
||
|
||
(check-expect (tab-sqr 3) (list 9 4 1 0)) | ||
|
||
(define (tab-sqr n) | ||
(tabulate sqr n)) | ||
|
||
(check-within (tab-tan 3) (list (tan 3) (tan 2) (tan 1) (tan 0)) 0.000001) | ||
|
||
(define (tab-tan n) | ||
(tabulate tan n)) | ||
|
||
|
||
(define (tab-sin n) | ||
(cond | ||
[(= n 0) (list (sin 0))] | ||
[else | ||
(cons | ||
(sin n) | ||
(tab-sin (sub1 n)))])) | ||
|
||
(define (tab-sqrt n) | ||
(cond | ||
[(= n 0) (list (sqrt 0))] | ||
[else | ||
(cons | ||
(sqrt n) | ||
(tab-sqrt (sub1 n)))])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#lang racket | ||
|
||
(check-expect (fold1 '(1 2 3 4 5) 0 +) (sum '(1 2 3 4 5))) | ||
(check-expect (fold1 '(1 2 3 4 5) 1 *) (product '(1 2 3 4 5))) | ||
|
||
(define (fold1 l i g) | ||
(cond | ||
[(empty? l) i] | ||
[else | ||
(g (first l) | ||
(fold1 (rest l) i g))])) | ||
|
||
|
||
(check-expect (fold1-sum '(1 2 3 4 5)) (+ 1 2 3 4 5)) | ||
|
||
(define (fold1-sum l) | ||
(fold1 l 0 +)) | ||
|
||
|
||
(check-expect (fold1-product '(1 2 3 4 5)) (* 1 2 3 4 5)) | ||
|
||
(define (fold1-product l) | ||
(fold1 l 1 *)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#lang racket | ||
|
||
(define LO-N1 (list 1 2 3 4 5 6)) | ||
(define LO-POSN1 (list (make-posn 20 30) (make-posn 40 70) (make-posn 50 50))) | ||
|
||
(define emt | ||
(empty-scene 100 100)) | ||
(define dot | ||
(circle 3 "solid" "red")) | ||
|
||
|
||
(check-expect (fold2 LO-N1 1 *) (product LO-N1)) | ||
(check-expect (fold2 LO-POSN1 emt place-dot) (image* LO-POSN1)) | ||
|
||
(define (fold2 l i g) | ||
(cond | ||
[(empty? l) i] | ||
[else | ||
(g (first l) | ||
(fold2 (rest l) i g))])) | ||
|
||
|
||
(check-expect (fold2-product LO-N1) (product LO-N1)) | ||
|
||
(define (fold2-product l) | ||
(fold2 l 1 *)) | ||
|
||
|
||
(check-expect (fold2-image* LO-POSN1) (image* LO-POSN1)) | ||
|
||
(define (fold2-image* l) | ||
(fold2 l emt place-dot)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#lang racket | ||
|
||
(check-expect (number? 5) #true) | ||
|
||
(check-expect (equal? #true "abde") #false) | ||
|
||
(check-expect (+ 1 2 3) 6) | ||
|
||
(check-expect (list 5) (list 5)) | ||
|
||
(check-expect (list? '(1 2 3 4)) #true) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#lang racket | ||
|
||
(check-expect (argmax second (list (list "a" 4) (list "b" 2) (list "c" 9) (list "d" 5))) | ||
(list "c" 9)) |