The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Apr 2017 |
| Last Sign in: | 103 Weeks Ago, 3 Days Ago |
| Questions Answered: | 4870 |
| Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
Here are 3 problems about Racket Programming Language:
Question #1:
Define and test a procedure memv that takes an element and a list and returns the first cdr whose car is eqv? to the element, or #f if the element is absent from the list.
> Â (memv 'a '(a b c))
'(a b c)
>Â Â (memv 'b '(a ? c))
#f
>Â (memv 'b '(a b c b))
'(b c b)
Â
Question #2:
The cartesian-product is defined over a list of sets (again simply lists that by our agreed upon convention don't have duplicates). The result is a list of tuples (i.e. lists). Each tuple has in the first position an element of the first set, in the second position an element of the second set, etc. The output list should contains all such combinations. The exact order of your tuples may differ; this is acceptable.
> Â (cartesian-product '((5 4) (3 2 1)))
((5 3) (5 2) (5 1) (4 3) (4 2) (4 1))
Â
Question #3:
The procedure powerset takes a list and returns the power set of the elements in the list. The exact order of your lists may differ; this is acceptable.
> Â (powerset '(3 2 1))
'((3 2 1) (3 2) (3 1) (3) (2 1) (2) (1) ())
>Â Â (powerset '())
'(( ))