I need code that will produce the powerset ("set of all subsets") of a
set (i.e. list) .
For example :
(compute-powerset (theList)
(
... your code here...
))
should work as follows
(compute-powerset '(a b c)) ---> '((a b c) (a b) (a c) (b c) (a) (b) (c) nil)
This looks like a pain in the butt to write. I was wondering if anybody
already has this code. Any help is appreciated.
Thanks,
-Pankaj
In article <··················@andrew.cmu.edu> ·····@andrew.cmu.edu (Pankaj S. Mody) writes:
I need code that will produce the powerset ("set of all subsets") of a
set (i.e. list) .
(compute-powerset '(a b c)) ---> '((a b c) (a b) (a c) (b c) (a) (b) (c) nil)
This looks like a pain in the butt to write.
Not at all. I won't give you the code, since you will learn more by writing
it yourself (whether or not this is a homework assignment :-). However,
I will give this hint:
Compare the powerset of (a b c) with the powerset of (b c):
(b c): ( (b c) (b) (c) nil)
(a b c): ((a b c) (a b) (a c) (a)
(b c) (b) (c) nil)
The way I have written them highlights the relationship. This should make
a recursive solution obvious.
(I really don't know if this is homework you are asking us to do for you,
although it looks a lot like it. But if it is homework, consider that
maybe your teacher is also reading this newsgroup ... )
--
Lou Steinberg
uucp: {pretty much any major site}!rutgers!aramis.rutgers.edu!lou
internet: ···@cs.rutgers.edu
In article <··················@andrew.cmu.edu> "Pankaj S. Mody" <·····@andrew.cmu.edu> writes:
>I need code that will produce the powerset ("set of all subsets") of a
>set (i.e. list) .
>(compute-powerset '(a b c)) ---> '((a b c) (a b) (a c) (b c) (a) (b) (c) nil)
>This looks like a pain in the butt to write. I was wondering if anybody
>already has this code. Any help is appreciated.
This sounds very much like a homework problem from 15-211/212 or
15-381. I know students in these classes have been assigned such a
problem in the past.
--mark