-3

#lang racket

(define(rectangleList list rectangle1)(recursion list rectangle1'()))
;(define rectangleList(list '(2 4 6 1)'(1 8 4 4)'(0 5 4 0)))
;(define rectangle1 '(1 3 5 2))

(define(recursion rectangleList rectangle1 returnedList)
 (if(<(length rectangleList)1)
   returnedList

 (recursion(cdr rectangleList) rectangle1
  (if(Intersect(car rectangleList)rectangle1)
    (cons (car rectangleList) returnedList)
    returnedList
    )
 )

) )

(define(Intersect rectangleList rectangle1)
 (and(and(<(car rectangleList) (cadr rectangle1)))
      (and(> (cadr rectangleList) (car rectangle1)))
      (and(< (cdr rectangleList)(caddr rectangle1)))
      (and(> (caddr rectangleList) (cdr rectangle1)))))

I am having a problem with calling my racket code. I am unsure how to proceed. The code is taking a list of rectangles and then also taking a rectangle and seeing if the singular rectangle intersects with any of the other rectangles in the list. Then it should output the list of rectangles that it intersects with i.e Test Cases.

Problem Statement: Given a rectangle, R, and a list of rectangles, L, return the list containing the elements in L that intersect with R.

Any help on this matter would be greatly appreciated! :)

MareeSky
  • 1
  • 2
  • It is very confusing that you're using the name "rectangleList" for different things, but it seems like you know how to call a procedure, and then somehow forgot when you got to testing your code. – molbdnilo Nov 09 '21 at 09:36
  • Sorry, I don't understand what you mean. This comment does not help me. I was wondering how I would call this function to test it in Racket's test window. It keeps giving me this error. – MareeSky Nov 09 '21 at 15:03
  • You call a procedure in the same way as you did in the code; `(procedure argument1 argument2)` if you have two arguments. – molbdnilo Nov 09 '21 at 15:09
  • And please don't post pictures of code, or linkes to pictures of code. Post the code. DrRacket has a fully functional "Copy" command. – molbdnilo Nov 09 '21 at 15:11
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Nov 15 '21 at 07:18

1 Answers1

0
#lang racket

(define(rectangleList list rectangle1)(recursion list rectangle1'()))
;(define rectangleList(list '(2 4 6 1)'(1 8 4 4)'(0 5 4 0)))
;(define rectangle1 '(1 3 5 2))

;Recusion function
(define(recursion rectangleList rectangle1 returnedList)
  (if(<(length rectangleList)1)
    returnedList

 (recursion(cdr rectangleList) rectangle1
  (if(Intersect(car rectangleList)rectangle1)
    (cons (car rectangleList) returnedList)
    returnedList
    )
 )

) )

;Intersect function      
 (define(Intersect rectangleList rectangle1)
  ;R1.topx<R2.bottomx
   (and(and(< (list-ref rectangleList 0) (list-ref rectangle1 2)))
      ;R1.bottomx>R2.topx
      (and(> (list-ref rectangleList 2) (list-ref rectangle1 0)))
      ;R1.bottomy<R2.topy
      (and(< (list-ref rectangleList 3)(list-ref rectangle1 1)))
      ;R1.topy>R2.bottomy
      (and(> (list-ref rectangleList 1) (list-ref rectangle1 3)))))

You call it by:

(rectangleList ('(1 1 4 5) '(1 3 5 6)) '( 1 3 5 7))

MareeSky
  • 1
  • 2
  • 1
    Is this… an answer? Or is it just providing more details for your original question? If the former, you should edit your answer to provide more explanation of what resolved the issue. If the latter, it should be an edit to your question. – Jeremy Caney Nov 14 '21 at 01:01
  • I must agree, this answer is very confusing, please edit it and clarify if this is a solution and if, then how have you solved the issue. – Ruli Nov 14 '21 at 04:26