#lang racket
(define-syntax cons-stream
  (syntax-rules ()
    ((cons-stream h t) (cons h (delay t)))))

(define head car)

(define (tail s) (force (cdr s)))

(define (map-stream f . streams)
  (cons-stream (apply            f (map head streams))
               (apply map-stream f (map tail streams))))

(define (filter-stream p? s)
  (if (p? (head s))
      (cons-stream (head s) (filter-stream p? (tail s)))
                            (filter-stream p? (tail s))))

(define (take n xs)
  (if (or (null? xs) (= n 0))
      '()
      (cons (head xs)
            (take (- n 1) (tail xs)))))

(define (1+ n) (+ 1 n))
(define nats
  (cons-stream 1
               (map-stream 1+ nats)))
 
(define nat-pairs
   (map-stream (lambda (x)
                (map-stream (lambda (y)
                              (cons x y))
                            nats))
              nats))

(define (generateExponents k l)
  'not-defined)




(define (value bins)
  (if (null? bins)
      0
      (+ (car bins)
         (* 2 (value (cdr bins))))))

(define (sameAsCode-helper t path)
  (if (null? t)
      0
      (let ((x (car t))
            (left (cadr t))
            (right (caddr t)))
        (if (= x (value path))
            x
            (let ((x-left (sameAsCode-helper left (cons 0 path)))
                  (x-right (sameAsCode-helper right (cons 1 path))))
              (if (not (= 0 x-left))
                  x-left
                  x-right)
        )))))
(define (sameAsCode t)
  (sameAsCode-helper t '(1)))

(sameAsCode '(5 (3 () (2 () ())) (4 (6 () ()) ())))


Last modified: Friday, 20 January 2023, 8:18 PM