diff options
[FP/P04] Added work from practicum
1 files changed, 46 insertions, 0 deletions
| -rw-r--r-- | Year 2/Functional Programming/04-Practice-27.10.2022.rkt | 46 |
diff --git a/Year 2/Functional Programming/04-Practice-27.10.2022.rkt b/Year 2/Functional Programming/04-Practice-27.10.2022.rkt new file mode 100644 index 0000000..cfb1933 --- /dev/null +++ b/Year 2/Functional Programming/04-Practice-27.10.2022.rkt @@ -0,0 +1,46 @@ +#lang racket + +;;; Exercise 01 + +(define (10^len n) + (if (= n 0) + 1 + (* (10^len (quotient n 10)) 10))) + +(define (substr? a b) + (define (calc-iter b comp) + (cond [(= b 0) #f] + [(= (remainder (- b a) comp) 0) #t] + [else (calc-iter (quotient b 10) comp)])) + (calc-iter b (10^len a))) + +(substr? 123 5123783) + +;;; Exercise 02 + +(define (my-identity x) + x) + +(define (my-compose f g) + (lambda (x) (f (g x)))) + +(define (my-negate p?) + (not p?)) + +(define (my-curry f x) + ((curry f) x)) + +;;; Exercise 03 + +(define (difference F a b) + (- (F a) (F b))) + +;;; Exercise 04 + +(define f + (lambda (x) (* 2 x))) + +;;; Exercise 05 + +(define (derive f eps) + (lambda (x) (/ (- (f (+ x eps)) (f x)) eps))) |
