Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- "problem 1."
- (define (first s) (car s))
- (define (rest s) (cdr s))
- (define (merge-streams s t)
- (if (or (null? s) (null? t))
- '()
- (cons (first s) (lambda () (merge-streams (rest s) t)))))
- "problem 2."
- (define (merge-compress s t)
- (cond ((< (first s) (first t)) (cons (first s) (lambda () (merge-compress (rest s) t))))
- ((> (first s) (first t)) (cons (first t) (lambda () (merge-compress s (rest t)))))
- ((= (first s) (first t)) (cons (first s) (lambda () (merge-compress (rest s) (rest t)))))))
- "problem 3a."
- (define (c-add pair pair2)
- (cons (+ (car pair) (car pair2)) (+ (cdr pair) (cdr pair2))))
- (define (c-multiply pair pair2)
- (cons (- (* (car pair) (car pair2)) (* (cdr pair) (cdr pair2)))
- (+ (* (car pair) (cdr pair2)) (* (cdr pair) (car pair2)))))
- (define (c-length pair)
- (sqrt (+ (* (car pair) (car pair)) (* (cdr pair) (cdr pair)))))
- "problem 3b."
- (define (mandelbrot-sequence-trail z a)
- (cons a (lambda () (mandelbrot-sequence-trail z (c-add z (c-multiply a a))))))
- (define (mandelbrot-sequence z)
- (mandelbrot-sequence-trail z (cons 0 0)))
- "problem 3c."
- (define (s-map f s)
- (if (null? s)
- s
- (cons (f (car s))
- (lambda () (s-map f (rest s))))))
- (define (mandelbrot-sequence-length z)
- (s-map c-length (mandelbrot-sequence z)))
- "problem 4."
- (define (h-min H) (car H))
- (define (left H) (cadr H))
- (define (right H) (caddr H))
- (define (combine-heaps H1 H2)
- (cond ((null? H1) H2)
- ((null? H2) H1)
- ((< (h-min H1) (h-min H2))
- (create-heap (h-min H1)
- H2
- (combine-heaps (left H1) (right H1))))
- (else (create-heap (h-min H2)
- H1
- (combine-heaps (left H2) (right H2))))))
- (define (remove-minimum H)
- (combine-heaps (left H) (right H)))
- (define (sorted-stream-h H)
- (cons (h-min H) (lambda () (sorted-stream-h (remove-minimum H)))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement