Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
gaecoli authored Nov 1, 2020
1 parent fcd3c82 commit ccb44f0
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 0 deletions.
49 changes: 49 additions & 0 deletions Exercise_238.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#lang racket

(check-expect (inf-sup.v2 max (list 10 4 15 23 1 3 12 52 2)) 52)
(check-expect (inf-sup.v2 min (list 10 4 15 23 1 3 12 52 2)) 1)

(define (inf-sup.v2 f l)
(cond
[(empty? (rest l)) (first l)]
[else (f (first l) (inf-sup.v2 f (rest l)))]))

; Determines the smallest number on l
(check-expect (inf-2 (list 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1))
1)
(check-expect (inf-2 (list 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25))
1)

(define (inf-2 l)
(inf-sup.v2 min l))


(check-expect (sup-2 (list 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1))
25)
(check-expect (sup-2 (list 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25))
25)

(define (sup-2 l)
(inf-sup.v2 max l))

(check-expect (inf-sup > (list 5 4 3 23)) 23)
(check-expect (inf-sup < (list 1 4 2)) 1)

(define (inf-sup f l)
(cond
[(empty? (rest l)) (first l)]
[else
(if (f (first l)
(inf-sup f (rest l)))
(first l)
(inf-sup f (rest l)))]))

(check-expect (inf-1 (list 5 1 2)) 1)

(define (inf-1 l)
(inf-sup < l))

(check-expect (sup-1 (list 4 1 6)) 6)

(define (sup-1 l)
(inf-sup > l))
7 changes: 7 additions & 0 deletions Exercise_239.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#lang racket

(cons 1 (cons 2 '()))

(cons 23 (cons "a" '()))

(cons "yellow" (cons #true '()))
15 changes: 15 additions & 0 deletions Exercise_240.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#lang racket

(define-struct layer [stuff])

(define LSTR0 "abcd")
(define LSTR1 (make-layer "abcd"))
(define LSTR2 (make-layer (make-layer (make-layer "abcd"))))

(define LNUM0 4)
(define LNUM1 (make-layer 10))
(define LNUM2 (make-layer (make-layer (make-layer 2))))


(define LITEM1 (make-layer "abcd"))
(define LITEM2 (make-layer 10))
15 changes: 15 additions & 0 deletions Exercise_241.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#lang racket

(define NELT1 (cons 20 '()))
(define NELT2 (cons 5 (cons 10 '())))

(define NELB1 (cons #true '()))
(define NELB2 (cons #true (cons #false '())))


(define NEL-T1 NELT1)
(define NEL-T2 NELT2)


(define NEL-B1 NELB1)
(define NEL-B2 NELB2)
7 changes: 7 additions & 0 deletions Exercise_242.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#lang racket

(check-expect (occurs "a" (list "b" "a" "d" "e")) (list "d" "e"))
(check-expect (occurs "a" (list "b" "c" "d")) #f)

(define (occurs s los)
los)
9 changes: 9 additions & 0 deletions Exercise_243.rkt
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) '())))
7 changes: 7 additions & 0 deletions Exercise_244.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#lang racket

(define (f x) (x 10))

(define (f x) (x f))

(define (f x y) (x 'a y 'b))
22 changes: 22 additions & 0 deletions Exercise_245.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#lang racket

(check-expect (function=at-1.2-3-and-5.775? x y) #false)
(check-expect (function=at-1.2-3-and-5.775? x z) #false)

(define (function=at-1.2-3-and-5.775? f1 f2)
(and (= (f1 1.2) (f2 1.2))
(= (f1 3) (f2 3))
(= (f1 -5.775) (f2 -5.775))))


; Number -> Number
(define (x n)
(+ n 2))

; Number -> Number
(define (y n)
(- n 3.5))

; Number -> Number
(define (z n)
(* n (/ 5 3)))

0 comments on commit ccb44f0

Please sign in to comment.