Subsets of a Set

We want to list all the subsets of a given set.

A set is an unordered collection of unique things.

Unordered means that {Apple, Orange, Banana} is the same set as {Banana, Apple, Orange}.

Unique means that you can't have two of the same thing in a set. Officially, you can write {Apple, Orange, Apple, Banana} and it's the same set as in the previous paragraph, but we'll make the simplifying assumption that there will be no duplicates in the representation of a set.

A subset of a set is a set all of whose elements are elements of the original set. So, starting with the set {Apple, Orange, Banana} we can find one-element subsets such as {Banana} and two-element subsets such as {Apple, Banana}. We also consider the original set {Apple, Orange, Banana} to be a subset of itself, and so is the empty set {} with no elements.

  1. Write down all the subsets of {Apple, Orange, Banana}. How many are there?

We, of course, represent a set as a list of its elements, which is the official name for the things in a set. A list is an ordered sequence—you can meaningfully ask "what is the third item of this list?" But we'll agree that when using a list to represent a set, order doesn't count.

You're going to write the block subsets that takes a set (a list) as input, and reports a list of lists in which each item is a subset of the input list.

subsets of {Apple, Orange, Banana}

It doesn't matter in what order the subsets appear in the output list, but each subset must appear exactly once.

  1. If you prefer to solve puzzles without hints, write subsets now. It's a bit harder than the other examples before this one, so don't give up if you can't do it instantly.