Methods
C
E
P
Instance Public methods
combination(sample_size = self.length, &sampler)

Returns all possible combinations made from sample_size number of items from this list.

Parameters

sample_size
The length of each combination.
sampler
If given, each combination is passed to this block.
# File lib/inochi/util/combo.rb, line 70
    def combination(sample_size = self.length, &sampler)
      pnk_cnk_impl(sample_size, true, &sampler)
    end
combinations(&sampler)

Returns all possible combinations of all possible lengths.

Parameters

sampler
If given, each combination is passed to this block.
# File lib/inochi/util/combo.rb, line 84
    def combinations &sampler
      all_lengths_impl :combination, &sampler
    end
enumeration(sample_size = self.length, &sampler)

Returns all possible enumerations made from sample_size number of items from this list.

Parameters

sample_size
The length of each enumeration.
sampler
If given, each enumeration is passed to this block.
# File lib/inochi/util/combo.rb, line 20
    def enumeration(sample_size = self.length, &sampler)
      return [] if sample_size < 1

      results = []

      visitor = lambda do |parents|
        each do |child|
          result = parents + [child]

          if result.length < sample_size
            visitor.call result
          else
            yield result if block_given?
            results << result
          end
        end
      end

      visitor.call []
      results
    end
enumerations(&sampler)

Returns all possible enumerations of all possible lengths.

Parameters

sampler
If given, each enumeration is passed to this block.
# File lib/inochi/util/combo.rb, line 52
    def enumerations &sampler
      all_lengths_impl :enumeration, &sampler
    end
permutation(sample_size = self.length, &sampler)

Returns all possible permutations made from sample_size number of items from this list.

Parameters

sample_size
The length of each permutation.
sampler
If given, each permutation is passed to this block.
# File lib/inochi/util/combo.rb, line 102
    def permutation(sample_size = self.length, &sampler)
      pnk_cnk_impl(sample_size, false, &sampler)
    end
permutations(&sampler)

Returns all possible permutations of all possible lengths.

Parameters

sampler
If given, each permutation is passed to this block.
# File lib/inochi/util/combo.rb, line 116
    def permutations &sampler
      all_lengths_impl :permutation, &sampler
    end