Taken from http://dzone.com/snippets/calculate-all-combinations
977307
function(a) {
    var fn = function(n, src, got, all) {
      if (n === 0) {
        all.push(got);
        return;
      }

      for (var j = 0; j < src.length; j++) {
        fn(n - 1, src.slice(j + 1), got.concat([src[j]]), all);
      }
    };

    var excluded = excludedPlugins.map(function(plugin) {
      return 'plugins/' + plugin + '.js';
    });

    // Remove the plugins that we don't want to build
    a = a.filter(function(n) {
      return excluded.indexOf(n) === -1;
    });

    var all = [a];

    for (var i = 0; i < a.length; i++) {
      fn(i, a, [], all);
    }

    return all;
  }
611218
function createCombination(array, combinationLength) {
    array = (0, _array.excludeTheSame)(array);
    if (!(0, _is.isNumber)(combinationLength)) {
        throw new Error('combinationLength should be number');
    }
    if (combinationLength < 1 || combinationLength > array.length) {
        throw new Error('combinationLength should be in the correct range');
    }

    return __createCombination(array, combinationLength);
}
292183
def getallgroups(arr, k=-1):
    
    if k < 0:
        k = len(arr)
    return itertools.chain.from_iterable(itertools.combinations(set(arr), j)
                                         for j in range(1, k + 1))
1013182
public static String[] getAllPermutations(String[] alphabet, int wordLength) {

    // initialize our returned list with the number of elements calculated above
    String[] allLists = new String[(int) Math.pow(alphabet.length, wordLength)];

    // lists of length 1 are just the original elements
    if (wordLength == 1)
      return alphabet;
    else {
      // the recursion--get all lists of length 3, length 2, all the way up to 1
      String[] allSublists = getAllPermutations(alphabet, wordLength - 1);

      // append the sublists to each element
      int arrayIndex = 0;

      for (int i = 0; i < alphabet.length; i++) {
        for (int j = 0; j < allSublists.length; j++) {
          // add the newly appended combination to the list
          allLists[arrayIndex] = alphabet[i] + allSublists[j];
          arrayIndex++;
        }
      }

      return allLists;
    }
  }
135171
public function combinations($arrays, $i = 0)
    {
        if (!isset($arrays[$i])) {
            return [];
        }
        if ($i == count($arrays) - 1) {
            return $arrays[$i];
        }

        $tmp = $this->combinations($arrays, $i + 1);

        $result = [];

        foreach ($arrays[$i] as $v) {
            foreach ($tmp as $t) {
                $result[] = is_array($t) ?
                    array_merge([$v], $t) : [$v, $t];
            }
        }

        return $result;
    }
881948
function computeCombinationLength(elementNumber, combinationLength) {
    elementNumber = Number(elementNumber);
    combinationLength = Number(combinationLength);
    if (!_regex.regex.positiveInteger.test(String(elementNumber))) {
        throw new Error("elementNumber should be positiveNumber but got " + elementNumber);
    }
    if (!(_regex.regex.positiveInteger.test(String(combinationLength)) || combinationLength === 0)) {
        throw new Error("elementNumber should be positiveNumber or 0 but got " + combinationLength);
    }
    if (combinationLength > elementNumber) {
        throw new Error("The max value of combinationLength should be " + elementNumber + " but got " + combinationLength);
    }
    if (combinationLength === 0) {
        return 1;
    }
    return computeFactorial(elementNumber) / (computeFactorial(combinationLength) * computeFactorial(elementNumber - combinationLength));
}
260912
function getAllCombinations () {
  var combinations = [];
  date.forEach(function (tf) {
    resolution.forEach(function (rf) {
      dataType.forEach(function (sf) {
        combinations.push(getCombination(tf, rf, sf));
      });
    });
  });

  return combinations;
}
778678
function() {

      var t;
      var a = this['n'];
      var b = this['d'];
      var res = [];

      if (isNaN(this['n']) || isNaN(this['d'])) {
        return res;
      }

      do {
        res.push(Math.floor(a / b));
        t = a % b;
        a = b;
        b = t;
      } while (a !== 1);

      return res;
    }
544373
def exactly_n(l, n=1):
    '''
    
    '''
    i = iter(l)
    return all(any(i) for j in range(n)) and not any(i)
1198824
protected double scoreCombination(double[] multiScore) {
		double sum = 0.0;
		for (int i=0; i<multiScore.length; i++) {
			sum += multiScore[i];
		}
		return sum/multiScore.length;
	}
1274771
def build_combinations
      @round += 1
      ExperimentCombinations.new(
        round: @round,
        occurrences_count: search_cases.size,
        ok_experiments: @ok_experiments,
        fail_experiments: @fail_experiments
      ).generate_combinations
    end
702923
def combination(n)
      raise Erlang::ImproperListError if improper?
      return Erlang::Cons.new(Erlang::Nil) if n == 0
      return self if empty?
      return tail.combination(n - 1).map { |list| list.cons(head) }.append(tail.combination(n))
    end
1212566
def combine_locks(locks):
    """"""
    all_locks = []
    for lock in locks:
        if isinstance(lock, CombinedLock):
            all_locks.extend(lock.locks)
        elif lock is not None:
            all_locks.append(lock)

    num_locks = len(all_locks)
    if num_locks > 1:
        return CombinedLock(all_locks)
    elif num_locks == 1:
        return all_locks[0]
    else:
        return DummyLock()
365861
private void generatePermutations(
      ArrayList<HashMap<String, String[]>[]> result, int index,
      HashMap<String, String[]>[][] subResult) {
    int localIndex = index;
    HashMap<String, String[]>[] value = subResult[localIndex];
    if (localIndex == 0) {
      for (int i = 0; i < value.length; i++) {
        HashMap<String, String[]>[] resultItem = new HashMap[subResult.length];
        resultItem[localIndex] = value[i];
        result.add(resultItem);
      }
    } else {
      ArrayList<HashMap<String, String[]>[]> newResult = new ArrayList<>();
      for (int e = 0; e < result.size(); e++) {
        for (int i = 0; i < value.length; i++) {
          HashMap<String, String[]>[] resultItem = result.get(e);
          resultItem[localIndex] = value[i];
          newResult.add(resultItem);
        }
      }
      result.clear();
      result.addAll(newResult);
    }
    localIndex++;
    if (localIndex < subResult.length) {
      generatePermutations(result, localIndex, subResult);
    }
  }
38111
def scenarios(self, generate_seed=False):
        
        seed = prime_numbers(1000)
        sweeps_all = self.experiment["sweeps"].keys()
        if "combinations" in self.experiment:
            if isinstance(self.experiment["combinations"], list):
                # For backward compatibility with experiments1-4s
                combinations_in_experiment = {" ": self.experiment["combinations"]}
                # if self.experiment["combinations"] == []:
                #    # Special notation for fully-factorial experiments
                #    combinations_in_experiment = {" ":[[],[]]}
            else:
                # Combinations must be a dictionary in this particular case
                combinations_in_experiment = self.experiment["combinations"]
        else:
            # Support no combinations element:
            combinations_in_experiment = dict()    # empty dict 

        # 1) calculate combinations_sweeps (depends on ALL combinations_ items)
        # Get the list of fully factorial sweeps
        all_combinations_sweeps = []
        all_combinations = []
        for key, combinations_ in combinations_in_experiment.items():
            # generate all permutations of all combinations
            if not combinations_:
                # Fully factorial experiment, shortcut for "combinations":[[],[]]
                combinations_sweeps = []
                combinations = [[]]
            else:
                # First item in combinations list is a list of sweeps
                combinations_sweeps = combinations_[0]
                # then - all combinations
                combinations = combinations_[1:]
            for item in combinations_sweeps:
                # TODO: error if sweep is already in this list?
                all_combinations_sweeps.append(item)
            all_combinations.append((combinations_sweeps, combinations))
        
        sweeps_fully_factorial = list(set(sweeps_all) - set(all_combinations_sweeps))
        # print "fully fact: %s" % sweeps_fully_factorial
        
        # 2) produce a list of all combinations of fully factorial sweeps
        # First sets of "combinations": the fully-factorial sweeps
        for sweep in sweeps_fully_factorial:
            all_combinations.append(([sweep], [[x] for x in self.experiment["sweeps"][sweep].keys()]))
        
        # 3) take the dot (inner) product of the list above (fully factorial arm combinations)
        #   with the first combinations list, that with the second combination list, ...
        # step-by-step reduce the list of combinations to a single item
        # (dot-product of each list of combinations)
        # this could use a lot of memory...
        red_iter = 0
        # print "all combinations:", red_iter, all_combinations
        while len(all_combinations) > 1:
            comb1 = all_combinations[0]
            comb2 = all_combinations[1]
            new_sweeps = comb1[0] + comb2[0]
            new_combinations = [x+y for x in comb1[1] for y in comb2[1]]
            all_combinations = [(new_sweeps, new_combinations)] + all_combinations[2:]
            red_iter += 1
            # print "all combinations:", red_iter, all_combinations
        
        # 4) write out the document for each in (3), which should specify one arm for each
        #   sweep with no repetition of combinations
        sweep_names = all_combinations[0][0]
        combinations = all_combinations[0][1]
        for combination in combinations:
            scenario = Scenario(self._apply_combination(self.experiment["base"], sweep_names, combination))
            scenario.parameters = dict(zip(sweep_names, combination))

            if generate_seed:
                # Replace seed if requested by the user
                if "@seed@" in scenario.xml:
                    scenario.xml = scenario.xml.replace("@seed@", str(next(seed)))
                else:
                    raise(RuntimeError("@seed@ placeholder is not found"))
            yield scenario
1133625
private function _findPermutations($combination)
    {
        // If the combination only has 1 element, then the permutation is the same as the combination
        if (count($combination) <= 1) {
            return [$combination];
        }

        $permutationList = [];

        $startKey = $this->_processSubPermutations($combination, $permutationList);

        // Now that the first element has been rotated to the end, we calculate permutations until
        // we reach the first element which is now at the end of the combiatnion.
        $key = key($combination);
        while ($key != $startKey) {
            $this->_processSubPermutations($combination, $permutationList);
            $key = key($combination);
        }

        return $permutationList;
    }
572414
def p(i, sample_size, weights):
        

        # Determine the initial pick values
        weight_i = weights[i]
        weights_sum = sum(weights)

        # Build a list of weights that don't contain the weight `i`. This list will
        # be used to build the possible picks before weight `i`.
        other_weights = list(weights)
        del other_weights[i]

        # Calculate the probability
        probability_of_i = 0
        for picks in range(0, sample_size):

            # Build the list of possible permutations for this pick in the sample
            permutations = list(itertools.permutations(other_weights, picks))

            # Calculate the probability for this permutation
            permutation_probabilities = []
            for permutation in permutations:

                # Calculate the probability for each pick in the permutation
                pick_probabilities = []
                pick_weight_sum = weights_sum

                for pick in permutation:
                    pick_probabilities.append(pick / pick_weight_sum)

                    # Each time we pick we update the sum of the weight the next
                    # pick is from.
                    pick_weight_sum -= pick

                # Add the probability of picking i as the last pick
                pick_probabilities += [weight_i / pick_weight_sum]

                # Multiply all the probabilities for the permutation together
                permutation_probability = reduce(
                    lambda x, y: x * y, pick_probabilities
                    )
                permutation_probabilities.append(permutation_probability)

            # Add together all the probabilities for all permutations together
            probability_of_i += sum(permutation_probabilities)

        return probability_of_i