| Path: | permutations.rb |
| Last Update: | Sun Nov 06 10:21:41 Central Standard Time 2005 |
The Permutations class exposes an iterator that yields each of the permutations for numbers 0 .. n-1. This iterator is then used by Numeric and Array to expose permutations methods that likewise yield sequences of permutations.
The algorithm is simple:
5.permutations { |a| puts a.join(', ') }
%w(a b c d f).permutations { |a| puts a.join(', ') }