Question

The difference of 2 sets using lisp in Dr.Racket.

The difference of 2 sets using lisp in Dr.Racket.

Homework Answers

Answer #1

Code:

(define (difference a b)
(cond ((null? a) '()) ;;if first set is empty return empty set
((member (car a) b) (difference (cdr a) b)) ;;id first element is a member of second set, continue in rest
(else (cons (car a) (difference (cdr a) b))))) ;;else add that element difference set and continue

(define (memebr a list) ;;HELPER FUNCTION
(cond ((null? list) #f) ;;If list is empty returns false
((equal? a (car list)) #t) ;;if element is equal to first element of list returns true
(else (member a (cdr list)))));; else continue in rest of the list

Snapshot of Code and Output:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
How can you use recursion in lisp (clisp) to process infix. Example (Thisisinfix '(1 + 2...
How can you use recursion in lisp (clisp) to process infix. Example (Thisisinfix '(1 + 2 * ( 1 + 2)) = 7 (Thisisinfix '((1 + 2) * ( 1 + 2))) = 9 I need the general idea of how this works, not the full functional code. This also needs to be done not using any kind of variables such as let, or any sets, only recursion, however you can define other functions using defun if that helps. I...
In LISP, write a recursive function that takes an integer n and returns the summation of...
In LISP, write a recursive function that takes an integer n and returns the summation of n and all positive integers preceding it. ; e.g., passing 5 will return 15, which is 1+2+3+4+5. I have the worst skill when it comes to creating recursion in the LISP programming language. Any help at all would be appreciated.
Show that the symmetric difference of two sets is equal to the union of the two...
Show that the symmetric difference of two sets is equal to the union of the two sets minus the intersection of the two sets: (A\B)U(B\A)=(AUB)\(A intersect B).
You can only use built in Lisp functions and you cannot use setq function. Write a...
You can only use built in Lisp functions and you cannot use setq function. Write a function in Lisp called f7 that returns the element at a given location of a list. The locations start at 0. Example: (f7 ‘(c (a b) (d c) (x y)) 2) returns (d c)
2) Given sets A, B. Two sets are equivalent if there is a bijection between them....
2) Given sets A, B. Two sets are equivalent if there is a bijection between them. Prove A x B is equivalent to B x A using bijection
A shipment of 6 television sets contains 2 defective sets. A hotel makes a random purchase...
A shipment of 6 television sets contains 2 defective sets. A hotel makes a random purchase of 3 of the sets. If x is the number of defective sets purchased by the hotel, nd the cumulative distribution function of the random variable X representing the number of defective. Then using F(x), find (a) P(X = 1) (b) P(0 < X <=2).
Definition 1. The symmetric difference of two sets A and B is the set A△B defined...
Definition 1. The symmetric difference of two sets A and B is the set A△B defined by A△B = (A \ B) ∪ (B \ A). (a) Draw the Venn diagram for the symmetric difference. (b) Prove that A△B = (A ∪ B) \ (A ∩ B). (c) Prove A△A = ∅, A△∅ = A. (d) Prove that for sets A, B, we have A△B = A \ B if and only if B ⊆ A.
(1)Create a LISP function FLATTEN, a function that returns all the elements of an arbitrarily nested...
(1)Create a LISP function FLATTEN, a function that returns all the elements of an arbitrarily nested list in a single-level list. (FLATTEN ’((A B (R)) A C (A D ((A (B)) R) A))) should return (A B R A C A D A B R A). (2) Create a Lisp function EXP-EVAL, a function that evaluates an arithmetic expression. You may assume that the binary operators used for an arithmetic expression are: +, -, *, and /, and each of...
Write a LISP function that accepts two lists as it's only arguments. The function should return...
Write a LISP function that accepts two lists as it's only arguments. The function should return a new list with the arguments as it's elements. So, if you pass the function (a b c) and (1 2 3), the function should return ((a b c) (1 2 3)).
LISP [3 marks] Write a procedure called triangle that takes three numbers as arguments representing the...
LISP [3 marks] Write a procedure called triangle that takes three numbers as arguments representing the three side-lengths of a triangle. The procedure should classify the triangle and return one of the following strings: "Equilateral" "Isoceles" "Scalene". E.g. (triangle 2 3 4) → "Scalene" E.g. (triangle 2 3 2) → "Isoceles"
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT