summaryrefslogtreecommitdiff
path: root/coding-exercises/2/9.rkt
diff options
context:
space:
mode:
authorMike Vink <mike1994vink@gmail.com>2023-03-05 20:58:20 +0100
committerMike Vink <mike1994vink@gmail.com>2023-03-05 20:58:20 +0100
commit592ef89cb282ab33d6b10cacae711a4a8e6b1212 (patch)
treee945b18ad80cd466639ee2beee3de77da09f1144 /coding-exercises/2/9.rkt
parentad461cbbbf839d040cda5d38f72072bbc20b5e4f (diff)
start ch2
Diffstat (limited to 'coding-exercises/2/9.rkt')
-rw-r--r--coding-exercises/2/9.rkt38
1 files changed, 38 insertions, 0 deletions
diff --git a/coding-exercises/2/9.rkt b/coding-exercises/2/9.rkt
new file mode 100644
index 0000000..0525802
--- /dev/null
+++ b/coding-exercises/2/9.rkt
@@ -0,0 +1,38 @@
+#lang racket
+(provide
+ width)
+(require
+ "7.rkt"
+ "8.rkt"
+ "9.rkt")
+
+(define (width x)
+ (/ (- (upper-bound x) (lower-bound x)) 2))
+
+(define (print-sum)
+ (newline)
+ (println "*** (width SUM) == (SUM width) ***")
+ (define a (make-interval 1 8))
+ (define b (make-interval 3 8))
+ (define c (add-interval a b))
+ (define d (sub-interval a b))
+ (define add-width (lambda (x y) (+ (width x) (width y))))
+ (print-interval a) (newline) (println (width a))
+ (print-interval c) (newline) (println (width c))
+ (println (add-width a b))
+ (print-interval d) (newline) (println (width d))
+ (println (add-width a b)))
+(print-sum)
+
+(define (print-mul)
+ (newline) (println " http://community.schemewiki.org/?sicp-ex-2.9 ")
+ (newline) (println " *** Multiplication: two pairs of different intervals with same width *** ")
+ (newline) (println " Can also be check algebraicly")
+ (define a (make-interval 1 8))
+ (define b (make-interval 3 8))
+ (define c (make-interval 0 7))
+ (define d (make-interval 0 5))
+ (println (width (mul-interval a b)))
+ (newline)
+ (println (width (mul-interval c d))))
+(print-mul)