First off, I wanted to clarify that I understand that there are similar questions to what I am asking, but I have a very specific output case that I am trying to replicate.
I am trying to create a Scheme procedure that allows me to take a set and generate a list that shows all possible subsets of that set.
For example, if I call: (subsets '(a b c ))
I should get: '((a b c) (b c) (a c) (c) (a b) (b) (a) ())
(in that order specifically)
Here is what I have so far:
(define (subsets givenList)
(if (null? givenList)
(list null)
(let ((rest (subsets (cdr givenList))))
(append rest (map (lambda (x)
(cons (car givenList) x))
rest)))))
My output for this is: (() (c) (b) (b c) (a) (a c) (a b) (a b c))
but that is not the specific output that I am looking for.
Any suggestions?