From: "Peña, Botp" Date: 2008-07-07T14:13:12+09:00 Subject: Re: Array Combinations From: Pragash Mr. [mailto:gananapragasam@srishtisoft.com] # i am having an array for ex:[1,2,3,4] # from this array i want to find the possible combinations like # [1,3,4,2] # [1,4,2,3] # etc.... if you have ruby version 1.8.7 or 1.9, just try it eg, > RUBY_VERSION => "1.8.7" > [1,2,3].permutation(3){|x| p x} [1, 2, 3] [1, 3, 2] [2, 1, 3] [2, 3, 1] [3, 1, 2] [3, 2, 1] => [1, 2, 3] > [1,2,3].permutation(2){|x| p x} [1, 2] [1, 3] [2, 1] [2, 3] [3, 1] [3, 2] => [1, 2, 3] > [1,2,3].combination(3){|x| p x} [1, 2, 3] => [1, 2, 3] > [1,2,3].combination(2){|x| p x} [1, 2] [1, 3] [2, 3] => [1, 2, 3] kind regards -botp