<commit_before>/**
 * jcombinatorics:
 * Java Combinatorics Library
 *
 * Copyright (c) 2009 by <NAME>.
 *
 * This software is made available under the terms of the MIT License.
 * See LICENSE.txt.
 *
 * Created Aug 30, 2009
 */
package jcombinatorics.combinations;

import java.util.Iterator;

import jcombinatorics.util.ArrayUtils;
import jcombinatorics.util.ReadOnlyIterator;

/**
 * A utility class that provides convenience methods for generating and working
 * with combinations.
 *
 * @author <NAME>
 * @see <a
 *      href="http://en.wikipedia.org/wiki/Combination">http://en.wikipedia.org/wiki/Combination</a>
 * @since 0.1
 */
public final class Combinations {

    /**
     * Utility classes should not have a public or default constructor.
     */
    private Combinations() {
        // noop
    }

    /**
     * Computes the number of unique combinations of <code>n</code> elements
     * taken <code>k</code> at a time, which can be computed as:
     * <code>n! / k! (n - k)!</code>
     *
     * @param n
     *        the number of elements
     * @param k
     *        subset/sample size
     * @return the number of combinations of <code>n</code> elements taken
     *         <code>k</code> at a time
     */
    public static long count(final int n, final int k) {
        if (k < 0 || k > n) {
            throw new IllegalArgumentException("0 <= k <= " + n + "!");
        }
        long count = n;
        for (int i = 1; i < k; ++i) {
            count = count * (n - i) / (i + 1);<commit_msg>Reverted 'optimization' of Combinations.count(n,k) which gave wrong result for count(0,k)<commit_after>/**
 * jcombinatorics:
 * Java Combinatorics Library
 *
 * Copyright (c) 2009 by <NAME>.
 *
 * This software is made available under the terms of the MIT License.
 * See LICENSE.txt.
 *
 * Created Aug 30, 2009
 */
package jcombinatorics.combinations;

import java.util.Iterator;

import jcombinatorics.util.ArrayUtils;
import jcombinatorics.util.ReadOnlyIterator;

/**
 * A utility class that provides convenience methods for generating and working
 * with combinations.
 *
 * @author <NAME>
 * @see <a
 *      href="http://en.wikipedia.org/wiki/Combination">http://en.wikipedia.org/wiki/Combination</a>
 * @since 0.1
 */
public final class Combinations {

    /**
     * Utility classes should not have a public or default constructor.
     */
    private Combinations() {
        // noop
    }

    /**
     * Computes the number of unique combinations of <code>n</code> elements
     * taken <code>k</code> at a time, which can be computed as:
     * <code>n! / k! (n - k)!</code>
     *
     * @param n
     *        the number of elements
     * @param k
     *        subset/sample size
     * @return the number of combinations of <code>n</code> elements taken
     *         <code>k</code> at a time
     */
    public static long count(final int n, final int k) {
        if (k < 0 || k > n) {
            throw new IllegalArgumentException("0 <= k <= " + n + "!");
        }
        long count = 1;
        for (int i = 0; i < k; ++i) {
            count = count * (n - i) / (i + 1);
{'fraction_non_alphanumeric': 0.1267650834403081, 'fraction_numerical': 0.010911424903722721, 'mean_word_length': 2.348012889366273, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1370137', 'n_tokens_mistral': 990, 'n_tokens_neox': 943, 'n_words': 316}