# Array Combinations

Hi,
I want to find array combinations is there any way find combinations in
array

On Mon, Jul 7, 2008 at 2:13 PM, Pragash Mr.
[email protected] wrote:

I want to find array combinations is there any way find combinations in
array

Yes.

If you want a more detailed answer, it might be a good idea to give an
appropriately detailed question…

Best Regards

Mikel

Mikel L. wrote:

On Mon, Jul 7, 2008 at 2:13 PM, Pragash Mr.
[email protected] wrote:

I want to find array combinations is there any way find combinations in
array

Yes.

If you want a more detailed answer, it might be a good idea to give an
appropriately detailed question…

Best Regards

Mikel

Hi,
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…

On Sun, Jul 6, 2008 at 9:35 PM, Pragash Mr.
[email protected] wrote:

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…

http://permutation.rubyforge.org/

martin

From: Pragash Mr. [mailto:[email protected]]

# 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