combinations.rb

Path: combinations.rb
Last Update: Sun Nov 06 10:29:28 Central Standard Time 2005

Combinations

Description

The Combinations class exposes a single method, each, which generates a sequence of arrays whose values are taken from (0..n-1), representing the combinations of that set taken k at a time.

The Array and Integer classes are extended with the combinations() method which likewise yield sequences of such combinations. For Array, the sequence consists of members of the original Array.

Examples

 5.combinations(3) { |a| puts a.join(', ') }
 %w(a b c d f).combinations(3) { |a| puts a.join(', ') }

Required files

factorial  

[Validate]