Hi,
I want to find array combinations is there any way find combinations in
array
···
--
Posted via http://www.ruby-forum.com/.
Hi,
I want to find array combinations is there any way find combinations in
array
--
Posted via http://www.ruby-forum.com/.
Yes.
If you want a more detailed answer, it might be a good idea to give an
appropriately detailed question... ![]()
Best Regards
Mikel
On Mon, Jul 7, 2008 at 2:13 PM, Pragash Mr. <gananapragasam@srishtisoft.com> wrote:
I want to find array combinations is there any way find combinations in
array
--
Rails, RSpec and Life blog....
Mikel Lindsaar wrote:
On Mon, Jul 7, 2008 at 2:13 PM, Pragash Mr. > <gananapragasam@srishtisoft.com> wrote:
I want to find array combinations is there any way find combinations in
arrayYes.
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....
--
Posted via http://www.ruby-forum.com/\.
http://permutation.rubyforge.org/
martin
On Sun, Jul 6, 2008 at 9:35 PM, Pragash Mr. <gananapragasam@srishtisoft.com> 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....
# 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
From: Pragash Mr. [mailto:gananapragasam@srishtisoft.com]