package brn.util;

import java.util.*;

/**
 * Some combinatorics: (n over k)
 */
public class Permu {

  private Set result = new HashSet();

  public List getResult() {
    return new ArrayList(result);
  }

  public void calcRec(int k, int n, Set used) {
    if (k > 0) {
      for (int i = 0; i < n; i++) {
        if (!(used.contains(new Integer(i)))) {
          HashSet nwUsed = new HashSet(used);
          nwUsed.add(new Integer(i));
          calcRec(k - 1, n, nwUsed);
        }
      }
    } else {
      result.add(used);
    }
  }

  public void calc(int k, int n) {
    calcRec(k, n, new HashSet());
  }


  public static void main(String[] args) {

    Permu perm = new Permu();

    perm.calc(2, 5);

    for (Iterator it = perm.result.iterator(); it.hasNext();) {
      Set s = (Set) it.next();
      String rs = new String();
      for (Iterator it2 = s.iterator(); it2.hasNext();) {
        Integer integer = (Integer) it2.next();
        rs = rs + integer.toString();
        if (it2.hasNext())
          rs += ",";
      }
      System.out.println(rs);
      //System.out.println(s);
    }
    System.out.println("NO: " + perm.result.size());
  }
}
