code: public static int choose(int n, int k) {
          assert(n >= k);
          double val = 1;
          for (int i=1; i<=k; i++) {
              val *= (n - (k-i))/(double)i;
          }
          return (int)val;
      }
docs: N choose K