All pastes #431538 Raw Edit

Plouj

public java v1 · immutable
·published 2007-04-09 19:02 UTC
rendered paste body
          public static <E> Set<Set<E>> powerset(Set<E> givenSet) {                  LinkedList<E> givenSetList = new LinkedList<E>(givenSet);                  Set<Set<E>> powerSet = new LinkedHashSet<Set<E>>();                  for (int i = 0; i < Math.pow(2,givenSet.size()); i++ ) {                          Set<E> subSet = new LinkedHashSet<E>();                          for (E e: givenSetList) {                                  if ((i % (int)Math.pow(2,givenSetList.indexOf(e)) ) == 0) {                                          System.out.println(i+" % "+(int)Math.pow(2,givenSetList.indexOf(e))+" :added "+g                                          subSet.add(e);                                  }                          }                          System.out.println(i+" "+Integer.toBinaryString(i)+" one subset is "+subSet);                          powerSet.add(subSet);                  }                  return powerSet;          }