Set of All Subsets

Given an array of items, create a set of all subsets of the items. The result is also called a powerset.

Set allSubsets(Array items) {
  if (items == null || items.length == 0) {
    Set s = new Set()
    s.put(new Set())
    return s

  Item item = items.removeFirst
  Set sets = allSubsets(items)
  Set newSets = sets.copy()
  for (set in sets) {

  return newSets

Scroll to top