Skip to content

Commit

Permalink
solutions
Browse files Browse the repository at this point in the history
  • Loading branch information
gaecoli committed Oct 25, 2020
1 parent a80deb8 commit fcd3c82
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 0 deletions.
37 changes: 37 additions & 0 deletions II - Arbitrarily-Large-Data/Exercise_233.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#lang racket

(check-expect `(0 ,@'(1 2 3) 4)
(list 0 1 2 3 4))

(check-expect `(("alan" ,(* 2 500))
("barb" 2000)
(,@'("carl" " , the great") 1500)
("dawn" 2300))
(list (list "alan" 1000)
(list "barb" 2000)
(list "carl" " , the great" 1500)
(list "dawn" 2300)))

(check-expect `(html
(body
(table ((border "1"))
(tr ((width "200"))
,@(make-row '( 1 2)))
(tr ((width "200"))
,@(make-row '(99 65))))))
(list 'html
(list 'body
(list 'table (list (list 'boder "1"))
(list 'tr (list (list 'width "200")) (list 'td "1") (list 'td "2"))
(list 'tr (list (list 'width "200")) (list 'td "99") (list 'td "65"))))))


(define (make-row l)
(cond
[(empty? l) '()]
[else (cons (make-cell (first l))
(make-row (rest l)))]))


(define (make-cell n)
`(td ,(number->string n)))
15 changes: 15 additions & 0 deletions II - Arbitrarily-Large-Data/Exercise_234.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#lang racket

(define one-list
'("Asia: Heat of the Moment"
"U2: One"
"The White Stripes: Seven Nation Army"))

(define (ranking los)
(reverse (add-ranks (reverse los))))

(define (add-ranks los)
(cond
[(empty? los) '()]
[else (cons (list (length los) (first los))
(add-ranks (rest los)))]))
26 changes: 26 additions & 0 deletions II - Arbitrarily-Large-Data/Exercise_235.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#lang racket

(check-expect (contains-atom? '("abcd" "efgh" "ijkl")) #false)
(check-expect (contains-atom? '("abcd" "atom" "efgh")) #true)

(define (contains-atom? l)
(contains? "atom" l))

(check-expect (contains-basic? '("abcd" "efgh" "ijkl")) #false)
(check-expect (contains-basic? '("abcd" "basic" "efgh")) #true)

(define (contains-basic? l)
(contains? "basic" l))

(check-expect (contains-zoo? '("abcd" "efgh" "ijkl")) #false)
(check-expect (contains-zoo? '("abcd" "zoo" "efgh")) #true)

(define (contains-zoo? l)
(contains? "zoo" l))


(define (contains? s l)
(cond
[(empty? l) #false]
[else (or (string=? (first l) s)
(contains? s (rest l)))]))
49 changes: 49 additions & 0 deletions II - Arbitrarily-Large-Data/Exercise_236.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#lang racket

(check-expect (plus 3 '(0 1 2 3 4)) '(3 4 5 6 7))
(check-expect (plus -2 '(0 1 2 3 4)) '(-2 -1 0 1 2))

(define (plus n l)
(cond
[(empty? l) '()]
[else (cons (+ (first l) n) (plus n (rest l)))]))


; Lon -> Lon
; Substract 2 from each number of a given list
(check-expect (sub2 '(2 3 4 5 6)) '(0 1 2 3 4))

(define (sub2 l)
(plus -2 l))

(check-expect (plus1 '(0 1 2 3 4)) '(1 2 3 4 5))

(define (plus1 l)
(plus 1 l))

(check-expect (plus5 '(0 1 2 3 4)) '(5 6 7 8 9))

(define (plus5 l)
(plus 5 l))


; adds 1 to each item on l
(check-expect (add1* '(0 1 2 3 4)) '(1 2 3 4 5))

(define (add1* l)
(cond
[(empty? l) '()]
[else
(cons
(add1 (first l))
(add1* (rest l)))])

(check-expect (plus5* '(0 1 2 3 4)) '(5 6 7 8 9))

(define (plus5* l)
(cond
[(empty? l) '()]
[else
(cons
(+ (first l) 5)
(plus5* (rest l)))]))
8 changes: 8 additions & 0 deletions II - Arbitrarily-Large-Data/Exercise_237.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#lang racket

(check-expect (squared>? 3 10) #false)
(check-expect (squared>? 4 10) #true)
(check-expect (squared>? 5 10) #true)

(define (squared>? x c)
(> (* x x) c))
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
| 10.11 | 5 | 219~223 | 16/25 | ... | ... | ... |
| 10.14 | 5 | 224~228 | 21/25 | ... | ... | ... |
| 10.18 | 4 | 229~232 | 25/25 | ... | ... | ... |
| 10.25 | 5 | 233~237 | 5/25 | ... | ... | ... |

----------------------------------------------------------------

Expand Down

0 comments on commit fcd3c82

Please sign in to comment.