From 377a71e7d657cda69f5fab88e4fcb5310b7e83ea Mon Sep 17 00:00:00 2001 From: Syndamia Date: Thu, 27 Oct 2022 11:02:52 +0300 Subject: [FP/P04] Added work from practicum --- .../04-Practice-27.10.2022.rkt | 46 ++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 Year 2/Functional Programming/04-Practice-27.10.2022.rkt (limited to 'Year 2/Functional Programming') 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))) -- cgit v1.3.1-23-gd82d