summaryrefslogtreecommitdiff
path: root/coding-exercises
diff options
context:
space:
mode:
Diffstat (limited to 'coding-exercises')
-rw-r--r--coding-exercises/2/83/install-complex.rkt6
-rw-r--r--coding-exercises/2/83/install-real.rkt2
-rw-r--r--coding-exercises/2/87.rkt15
3 files changed, 6 insertions, 17 deletions
diff --git a/coding-exercises/2/83/install-complex.rkt b/coding-exercises/2/83/install-complex.rkt
index e3dfe52..df46817 100644
--- a/coding-exercises/2/83/install-complex.rkt
+++ b/coding-exercises/2/83/install-complex.rkt
@@ -153,12 +153,6 @@
(make-from-mag-ang (mul (magnitude z1) (magnitude z2))
(add (angle z1) (angle z2))))
(define (div-complex z1 z2)
- (newline)
- (display "DIV-COMPLEX")
- (newline)
- (display (list z1 z2))
- (newline)
- (display (list (magnitude z1) (magnitude z2)))
(make-from-mag-ang (div (magnitude z1) (magnitude z2))
(sub (angle z1) (angle z2))))
diff --git a/coding-exercises/2/83/install-real.rkt b/coding-exercises/2/83/install-real.rkt
index 356ac92..45b1a6c 100644
--- a/coding-exercises/2/83/install-real.rkt
+++ b/coding-exercises/2/83/install-real.rkt
@@ -9,7 +9,7 @@
(attach-tag 'real datum))
(define (make i)
(let ((n (exact->inexact i)))
- (if (< n threshold)
+ (if (< (abs n) threshold)
0.0
n)))
(define (raiseme r)
diff --git a/coding-exercises/2/87.rkt b/coding-exercises/2/87.rkt
index d697781..4624dda 100644
--- a/coding-exercises/2/87.rkt
+++ b/coding-exercises/2/87.rkt
@@ -263,11 +263,6 @@
(list (the-empty-termlist L1) L1)
(let ((new-c (div (coeff t1) (coeff t2)))
(new-o (- (order t1) (order t2))))
- (display (list new-c new-o t1 t2 (sub-terms L1
- (mul-terms
- (make-term-list (list (make-term new-o new-c)))
- L2))))
- (newline)
(let ((rest-of-result (div-terms
(sub-terms L1
(mul-terms
@@ -320,10 +315,11 @@
(term 1 test-integer))))
(define test-poly2 (make-polynomial 'x (sparse-termlist
(term 100 test-complex)
+ (term 2 test-real)
(term 1 test-rat)
(term 0 test-integer))))
(define test-poly3 (make-polynomial 'x (sparse-termlist
- (term 1 2)
+ (term 50 test-rat)
(term 0 2))))
((lambda ()
(newline)
@@ -366,7 +362,7 @@
(display (sub test-dense-poly test-poly3))))
;; 91
-;; Fill in the gaps excercise, should be easy right? :^)
+;; Fill in the gaps excercise, should be easy right? :^) (NOTE(mike): it wasn't.)
((lambda ()
(newline)
(display (div test-poly3 test-poly3))
@@ -374,8 +370,7 @@
(display (div (make-polynomial 'x (dense-termlist (term 3 100)))
(make-polynomial 'x (dense-termlist (term 3 10)))))
(newline)
+ (display (div test-poly2 test-poly1))
(newline)
- (display (list test-poly2 test-poly1))
(newline)
- (newline)
- (display (div test-poly2 test-poly1))))
+ (display (div test-poly2 test-poly3))))