void getBitCombinations(BitSet bs, int start, int current, int target)
{
    if (current == target) {
		// success, so process the combination 
		// (clone 'bs' so that we're sure it's not modified)
		foo.combinationHandlerMethod((BitSet) bs.clone());
		return;
    }
    if (start == a.length)
        return;					// failure

    bs.set(start);
    current++;
    getBitCombinations(bs, start + 1, current, target);

    bs.clear(start);
    current--;
    getBitCombinations(bs, start + 1, current, target);
}

Example 2: A version of the code that passes solutions to a function that the code's author determines at or before compile time.

Back to Article