Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Exercise: Rectangle library, power-set, and inclusion-exclusion principle (provide rect rect? rect-area rect-list-intersect all-sub-rectangles total-rect-area power-set) ; power-set: takes an arbitrary Racket (set) and returns its

Exercise: Rectangle library, power-set, and inclusion-exclusion principle

(provide rect rect? rect-area rect-list-intersect all-sub-rectangles total-rect-area power-set)

; power-set: takes an arbitrary Racket (set) and returns its power-set, the set of all its subsets (define (power-set st) '(if (null? st) '(()) (let ((rest (power-set (cdr st)))) (append rest (map (lambda (x) (cons (car set) x)) rest)))))

1) total-rect-area: takes a list of rectangles (defined in e2) and returns the total covered area Note: do not double-count area covered by >1 rectangles E.g., (total-rect-area '((rect 0 0 2 2) (rect 1 1 3 3))) => 7 ;Hint: use the power-set function and the inclusion-exclusion principle; review your functions from e2 (define (total-rect-area rect-list) 'todo)

Write the implementation of this one.

2) Compute a Racket (set) of all sub-rectangles in the given rectangle We will call any rectangle r', with integer side-lengths of at least 1, a "sub-rectangle" of r iff r fully contains r' E.g., (all-sub-rectangles (rect 0 0 0 0)) => (set) E.g., (all-sub-rectangles (rect 0 0 1 1)) => (set `(rect 0 0 1 1)) E.g., (all--sub-rectangles (rect 10 5 11 7)) => (set `(rect 10 5 11 7) `(rect 10 5 11 6) `(rect 10 6 11 7)) Hint: can you solve this using the `foldl` and `range` functions? (define (all-sub-rectangles r) 'todo)

Write implementation of this one also.

3) Any two opposing corners of a grid-aligned rectangle as pairs (x0,y0), (x1,y1) `(rect ,lower-left-x ,lower-left-y ,upper-right-x ,upper-right-y) (define (rect x0 y0 x1 y1) ; return a normalized rect-tagged s-expr representation of the rectangle 'todo)

Write implementation of this one also.

4) Predicate defining a rectangle (define (rect? r) 'todo)

Write implementation of this one also.

5) Given a rect?, yield its (integer?) area (define (rect-area rect) 'todo)

Write implementation of this one also.

6) Compute the intersection of a list of one or more rectangles E.g., the list `((rect 0 0 10 10) (rect 0 -5 10 1) (rect -5 -5 2 5))

has intersection `(rect 0 0 2 1) (define (rect-list-intersect rect-list) 'todo)

Write implementation of this one also.

Please write racket code in place of todo in above questions.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Managing Your Information How To Design And Create A Textual Database On Your Microcomputer

Authors: Tenopir, Carol, Lundeen, Gerald

1st Edition

1555700233, 9781555700232

More Books

Students also viewed these Databases questions